//Tanuj Khattar
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> II;
typedef vector< II > VII;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long int LL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
const int N = int(1e5)+10;
const int LOGN = 20;
int U[N],V[N],W[N],done[N],Start[LOGN][N],End[LOGN][N],E[N],sub[N],idx[N],level[N],par[N];
vector<LL> BIT[N];
VI g[N];
map<II,int> mp;
int adj(int u,int e)
{
return U[e]==u?V[e]:U[e];
}
/************************ BIT **************************/
void update(vector<LL>& BIT,int x,LL add)
{
for(;x<SZ(BIT);x+=(x^(x&(x-1))))
BIT[x]+=add;
}
LL query(vector<LL>& BIT,int x)
{
LL ret=0;
for(;x;x=x&(x-1))ret+=BIT[x];
return ret;
}
/******************* Centroid Decomposition ********************/
int nn=0;
void dfs0(int u,int ee)
{
sub[u]=1;nn++;
for(auto e:g[u])
if(e!=ee && !done[e])
{
int w = adj(u,e);
dfs0(w,e);
sub[u]+=sub[w];
}
}
int dfs1(int u,int ee)
{
for(auto e:g[u])
if(e!=ee && !done[e])
{
int w = adj(u,e);
if(sub[w]>nn/2)
return dfs1(w,e);
}
return u;
}
int lvl,T,cid=-1;
void dfs2(int u,int ee,LL dist=0)
{
Start[lvl][u]=++T;
update(BIT[cid],T,dist);
update(BIT[cid],T+1,-dist);
for(auto e:g[u])
if(e!=ee && !done[e])
{
int w = adj(u,e);
dfs2(w,e,dist+W[e]);
}
End[lvl][u]=T;
}
void decompose(int u,int p)
{
nn=0;dfs0(u,-1);
int root = dfs1(u,-1);
par[root]=p;lvl=level[root]=level[p]+1;
idx[root]=++cid;BIT[cid] = vector<LL>(nn+2,0);
T=0;dfs2(root,-1);
for(auto e:g[root]){
if(done[e])continue;
done[e]=1;E[e]=root;
decompose(adj(root,e),root);
}
}
/*********************** Handle the queries ***************************/
LL ans[N],dist[LOGN][N],cntbn[N],vis[N];
int Q[N],k,test;
pair<LL,LL> best[N],inf;
void go()
{
//clear
for(int i=0;i<k;i++){
int x = Q[i];
while(x)
best[x]=inf,cntbn[x]=0,vis[x]=0,x=par[x];
}
//find cntbn
for(int i=0;i<k;i++){
int x = Q[i],y=par[x];
best[x].F=max(best[x].F,0ll);
while(y)
{
LL d = query(BIT[idx[y]],Start[level[y]][Q[i]]);
dist[level[y]][Q[i]]=d;
cntbn[x]=max(cntbn[x],d);
x = par[x];y=par[y];
}
}
//find best
for(int i=0;i<k;i++){
int x = Q[i],y=par[x];
while(y)
{
if(!vis[x])
{
vis[x]=1;
LL d = cntbn[x];
if(d>best[y].F)best[y].S=best[y].F,best[y].F=d;
else if(d>best[y].S)best[y].S=d;
}
x = par[x],y = par[y];
}
}
//compute the answers
for(int i=0;i<k;i++){
int x = Q[i],y = par[x];
ans[i] = best[x].F;
while(y){
LL d1 = dist[level[y]][Q[i]];
LL d2 = (cntbn[x]==best[y].F?best[y].S:best[y].F);
ans[i]=max(ans[i],d1+d2);
x = par[x],y = par[y];
}
}
//done :)
}
int main()
{
inf={-LL(1e18),-LL(1e18)};
int n;si(n);
for(int i=1;i<n;i++)
{
scanf("%d %d %d",U+i,V+i,W+i);
g[U[i]].PB(i);
g[V[i]].PB(i);
mp[MP(min(U[i],V[i]),max(U[i],V[i]))]=i;
}
decompose(1,0);
int q;si(q);
while(q--)
{
test++;
int t;si(t);
if(t==1)
{
int u,v;LL w;
si(u);si(v);sll(w);
if(u>v)swap(u,v);
int e = mp[MP(u,v)],x = E[e];
while(x){
int y = (Start[level[x]][u]>Start[level[x]][v]?u:v);
update(BIT[idx[x]],Start[level[x]][y],w - W[e]);
update(BIT[idx[x]],End[level[x]][y]+1,W[e] - w);
x = par[x];
}
W[e]=w;
}
else
{
si(k);
for(int i=0;i<k;i++)si(Q[i]);
go();
for(int i=0;i<k;i++)printf("%lld ",ans[i]);
printf("\n");
}
}
return 0;
}
Ly9UYW51aiBLaGF0dGFyCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBwYWlyPGludCxpbnQ+ICAgSUk7CnR5cGVkZWYgdmVjdG9yPCBJSSA+ICAgICAgVklJOwp0eXBlZGVmIHZlY3RvcjxpbnQ+ICAgICBWSTsKdHlwZWRlZiB2ZWN0b3I8IFZJID4gCVZWSTsKdHlwZWRlZiBsb25nIGxvbmcgaW50IAlMTDsKCiNkZWZpbmUgUEIgcHVzaF9iYWNrCiNkZWZpbmUgTVAgbWFrZV9wYWlyCiNkZWZpbmUgRiBmaXJzdAojZGVmaW5lIFMgc2Vjb25kCiNkZWZpbmUgU1ooYSkgKGludCkoYS5zaXplKCkpCiNkZWZpbmUgQUxMKGEpIGEuYmVnaW4oKSxhLmVuZCgpCiNkZWZpbmUgU0VUKGEsYikgbWVtc2V0KGEsYixzaXplb2YoYSkpCgojZGVmaW5lIHNpKG4pIHNjYW5mKCIlZCIsJm4pCiNkZWZpbmUgZG91dChuKSBwcmludGYoIiVkXG4iLG4pCiNkZWZpbmUgc2xsKG4pIHNjYW5mKCIlbGxkIiwmbikKI2RlZmluZSBsbGRvdXQobikgcHJpbnRmKCIlbGxkXG4iLG4pCiNkZ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