#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
#define debug cout<<"YES\n";
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=1e5+1e4;
const int lz=0;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){if(y==0) return x;return gcd(y,x%y);}
///存图
struct E{
int u,nxt,w;
}edge[maxn<<1];//前式链向星要比vector快
int head[maxn],tot=0;
void addedge(int x,int y,int z){
edge[tot]=E{y,head[x],z};
head[x]=tot++;
}
///线段树结构
int n,w[maxn],val[maxn],m;
int sum[maxn<<2],lazy[maxn<<2];
void pushup(int x){sum[x]=sum[x<<1]+sum[x<<1|1];}
void build(lrt){
lazy[rt]=lz;
if(l==r) {sum[rt]=w[l];return;}
int mid=l+r>>1;
build(lson),build(rson),pushup(rt);
}
void update(lrt,int pos,int v){
if(l==r){
sum[rt]=v;
return ;
}
int mid=l+r>>1;
if(pos<=mid) update(lson,pos,v);
if(mid<pos) update(rson,pos,v);
pushup(rt);
}
int query(lrt,int L,int R){
if(L<=l&&r<=R) return sum[rt];
int mid=l+r>>1,ans=0;
if(L<=mid) ans+=query(lson,L,R);
if(mid<R) ans+=query(rson,L,R);
return ans;
}
///第一次dfs
int fa[maxn],dep[maxn],sz[maxn],son[maxn];
void dfs1(int u,int f){
sz[u]=1,fa[u]=f,dep[u]=dep[f]+1;
for(int i=head[u];~i;i=edge[i].nxt){
int v=edge[i].u;
if(v==f) continue;
dfs1(v,u);
sz[u]+=sz[v];
if(sz[v]>sz[son[u]]) son[u]=v;
}
}
///第二次dfs
int tim,dfn[maxn],top[maxn];
void dfs2(int u,int f,int pre){///这里的f是top的意思
dfn[u]=++tim,top[u]=f,w[tim]=pre;
int tmp=0;
for(int i=head[u];~i;i=edge[i].nxt){
if(edge[i].u==son[u]){
tmp=edge[i].w;
break;
}
}
if(son[u]) dfs2(son[u],f,tmp);
for(int i=head[u];~i;i=edge[i].nxt){
int v=edge[i].u;
if(v==fa[u]||v==son[u]) continue;/坑点
dfs2(v,v,edge[i].w);
}
}
///对链操作
int query(int x,int y){
int ans=0;
while(top[x]^top[y]){
if(dep[top[x]]<dep[top[y]]) swap(x,y);
ans+=query(1,tim,1,dfn[top[x]],dfn[x]);
x=fa[top[x]];
}
if(dep[x]>dep[y]) swap(x,y);
if(x==y) return ans;
ans+=query(1,tim,1,dfn[son[x]],dfn[y]);
return ans;
}
int cur;
struct N{
int x,y,z;
}node[maxn<<1];
int main(){
/*
freopen("d://in.txt","r",stdin);
freopen("d://out.txt","w",stdout);*/
scanf("%d%d%d",&n,&m,&cur);
mst(head,-1);
rep(i,1,n){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
node[i]=N{x,y,z};
addedge(x,y,z);
addedge(y,x,z);
}
dfs1(1,0),dfs2(1,1,0);
build(1,tim,1);
rep(i,1,n) if(dep[node[i].x]<dep[node[i].y])
swap(node[i].x,node[i].y);
int x,y,z;
while(m--){
scanf("%d",&x);
if(x){
scanf("%d%d",&y,&z);
update(1,n,1,dfn[node[y].x],z);
}else{
scanf("%d",&y);
printf("%d\n",query(cur,y));
cur=y;
}
}
return 0;
}