import sys input = sys.stdin.readline N,Q=map(int,input().split()) Queries=[list(map(int,input().split())) for i in range(Q)] LIST=[[i] for i in range(N+1)] Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: LIST[find(y)].extend(LIST[find(x)]) LIST[find(x)]=[] Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: LIST[find(x)].extend(LIST[find(y)]) LIST[find(y)]=[] Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for t,a,b in Queries: if t==1: Union(a,b) X=[0] for i in range(1,N+1): X.extend(LIST[i]) X_INV=[-1]*(N+1) for ind,x in enumerate(X): X_INV[x]=ind Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 Last = [i for i in range(N+1)] def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Last[find(y)]=Last[find(x)] Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Last[find(x)]=Last[find(y)] Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) LEN=N+1 # 必要なら座標圧縮する seg_el=1<<((N+1).bit_length()) # Segment treeの台の要素数 SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 def getvalue(n,seg_el): # 一点の値を取得 i=n+seg_el ANS=0 ANS=SEG[i] i>>=1# 子ノードへ while i!=0: ANS+=SEG[i] i>>=1 return ANS def updates(l,r,x): # 区間[l,r)のminを更新. L=l+seg_el R=r+seg_el while L>=1 R>>=1 for t,a,b in Queries: if t==1: Union(a,b) elif t==2: updates(X_INV[find(a)],X_INV[Last[find(a)]]+1,b) else: print(getvalue(X_INV[a],seg_el))