from sys import setrecursionlimit def f(p,a,i): t=p[i] if t<0: return i,0 t,a=f(p,a,t) p[i]=t a[i]+=a return t,a[i] def u(p,a,i,j): i,_=f(p,a,i) j,_=f(p,a,j) if i==j: return p[j]+=p[i] p[i]=j a[i]-=a[j] setrecursionlimit(100000) N,Q=map(int,input().split()) p=[-1]*(N+1) a=[0]*(N+1) r=[] for _ in range(Q): T,A,B=map(int,input().split()) if T==1: u(p,a,A,B) elif T==2: j,_=f(p,a,A) a[j]+=B elif T==3: j,k=f(p,a,A) r.append(a[j]+k) print(*r,sep='\n')