#include<cstdio>
#include<queue>
#include<algorithm>
const int N=100005;
int es[N*2],enx[N*2],e0[N],ep=2;
int dep[N],sz[N],son[N],fa[N],top[N],id[N],idp=1;
int n,m;
void f1(int w,int pa){
fa[w]=pa;
dep[w]=dep[pa]+1;
sz[w]=1;
for(int i=e0[w];i;i=enx[i]){
int u=es[i];
if(u!=pa){
f1(u,w);
sz[w]+=sz[u];
if(sz[u]>sz[son[w]])son[w]=u;
}
}
}
void f2(int w,int tp){
top[w]=tp;
id[w]=idp++;
if(son[w])f2(son[w],tp);
for(int i=e0[w];i;i=enx[i]){
int u=es[i];
if(u!=fa[w]&&u!=son[w])f2(u,u);
}
}
struct heap{
std::priority_queue<int>m,d;
inline void ins(int x){
m.push(x);
}
inline void del(int x){
d.push(x);
}
inline int max(){
while(!d.empty()&&m.top()==d.top())m.pop(),d.pop();
if(m.empty())return -1;
return m.top();
}
}h[262144];
int l,r,x;
void ins(int w=1,int L=1,int R=131072){
if(l<=L&&R<=r){
h[w].ins(x);
return;
}
int M=L+R>>1;
if(l<=M)ins(w<<1,L,M);
if(r>M)ins(w<<1^1,M+1,R);
}
void del(int w=1,int L=1,int R=131072){
if(l<=L&&R<=r){
h[w].del(x);
return;
}
int M=L+R>>1;
if(l<=M)del(w<<1,L,M);
if(r>M)del(w<<1^1,M+1,R);
}
struct sg{int l,r;}ss[64];
bool operator<(sg a,sg b){return a.l<b.l;}
int sp;
inline void Ins(int x,int y){
sp=0;
ss[sp++]=(sg){0,0};
ss[sp++]=(sg){262145,262145};
int a=top[x],b=top[y],c;
while(a!=b){
if(dep[a]<dep[b])c=a,a=b,b=c,c=x,x=y,y=c;
ss[sp++]=(sg){id[a],id[x]};
x=fa[a];a=top[x];
}
if(dep[x]<dep[y])ss[sp++]=(sg){id[x],id[y]};
else ss[sp++]=(sg){id[y],id[x]};
std::sort(ss,ss+sp);
for(int i=1;i<sp;i++)if(ss[i-1].r+1<ss[i].l){
l=ss[i-1].r+1;r=ss[i].l-1;
ins();
}
}
inline void Del(int x,int y){
sp=0;
ss[sp++]=(sg){0,0};
ss[sp++]=(sg){262145,262145};
int a=top[x],b=top[y],c;
while(a!=b){
if(dep[a]<dep[b])c=a,a=b,b=c,c=x,x=y,y=c;
ss[sp++]=(sg){id[a],id[x]};
x=fa[a];a=top[x];
}
if(dep[x]<dep[y])ss[sp++]=(sg){id[x],id[y]};
else ss[sp++]=(sg){id[y],id[x]};
std::sort(ss,ss+sp);
for(int i=1;i<sp;i++)if(ss[i-1].r+1<ss[i].l){
l=ss[i-1].r+1;r=ss[i].l-1;
del();
}
}
inline void getmax(int w){
int a=-1,b;
for(w=id[w]+131071;w;w>>=1){
b=h[w].max();
if(b>a)a=b;
}
printf("%d\n",a);
}
int qa[N*2],qb[N*2],qv[N*2];
int main(){
scanf("%d%d",&n,&m);
for(int i=1,a,b;i<n;i++){
scanf("%d%d",&a,&b);
es[ep]=b;enx[ep]=e0[a];e0[a]=ep++;
es[ep]=a;enx[ep]=e0[b];e0[b]=ep++;
}
f1(1,0);f2(1,1);
for(int i=1;i<=m;i++){
int op,a,b,v;
scanf("%d",&op);
if(op==0){
scanf("%d%d%d",&a,&b,&v);
qa[i]=a;qb[i]=b;qv[i]=v;
x=v;
Ins(a,b);
}else if(op==1){
scanf("%d",&a);
x=qv[a];
Del(qa[a],qb[a]);
}else{
scanf("%d",&v);
getmax(v);
}
}
return 0;
}