#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5;
int tin[maxn], out[maxn], val[maxn], at[maxn], up[maxn], timedfs;
vector<pair<int, int>> g[maxn];
int st[4 * maxn], lazy[4 * maxn];
void apply(int id, int x){
st[id] += x;
lazy[id] += x;
}
void down(int id){
apply(id * 2, lazy[id]);
apply(id * 2 + 1, lazy[id]);
lazy[id] = 0;
}
void update(int id, int l, int r, int p, int x){
if(l == r) st[id] += x;
else{
down(id);
int mid = (l + r) / 2;
if(p <= mid) update(id * 2, l, mid, p, x);
else update(id * 2 + 1, mid + 1, r, p, x);
st[id] = min(st[id * 2], st[id * 2 + 1]);
}
}
void assign(int id, int l, int r, int u, int v, int x){
if(v < l || r < u) return;
if(u <= l && r <= v) apply(id, x);
else{
down(id);
int mid = (l + r) / 2;
assign(id * 2, l, mid, u, v, x);
assign(id * 2 + 1, mid + 1, r, u, v, x);
st[id] = min(st[id * 2], st[id * 2 + 1]);
}
}
void dfs(int u, int p){
tin[u] = ++timedfs;
for(auto [v, w]: g[u]){
if(v == p) continue;
val[v] = val[u] + w;
up[v] = w;
dfs(v, u);
}
out[u] = timedfs;
val[u] += 1e15;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, q; cin >> n >> q;
for(int i = 1; i <= n - 1; i++){
int u, v, w; cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
dfs(1, 0);
for(int i = 1; i <= n; i++) update(1, 1, n, tin[i], val[i]);
while(q--){
int type; cin >> type;
if(type == 1){
int q; cin >> q;
cout << st[1] << "\n";
}
if(type == 2){
int x; cin >> x;
update(1, 1, n, tin[x], (at[x] ? 1e15 : -1e15));
at[x] = !at[x];
}
if(type == 3){
int a, b, x; cin >> a >> b >> x;
if(tin[a] > tin[b]) swap(a, b);
assign(1, 1, n, tin[b], out[b], x - up[b]);
up[b] = x;
}
}
}