n, q = map(int, input().split()) # union-findを魔改造 groups = [[i] for i in range(n + 1)] # groupsには同グループすべての頂点を入れる par = [-1] * (n + 1) # parには根か、-sizeが入る add_edge = [0] * (n + 1) add_root = [0] * (n + 1) def find(x): if par[x] < 0: return x else: y = par[x] par[x] = find(y) return par[x] def size(x): return -par[find(x)] def unite(x, y): if find(x) == find(y): return False X = find(x) Y = find(y) if size(x) < size(y): # 必ずyのsizeが小さくする x, y = y, x X = find(x) Y = find(y) par[X] += par[Y] par[Y] = X # 各々の足し算結果の調整 rx = add_root[X] ry = add_root[Y] for i in range(len(groups[Y])): e = groups[Y][i] oldpy = add_edge[e] newpy = oldpy + (ry - rx) add_edge[e] = newpy add_root[Y] = 0 # group管理の調整 groups[X].extend(groups[Y]) groups[Y] = [] return True def query(x): X = find(x) return add_edge[x] + add_root[X] for _ in range(q): t, a, b = map(int, input().split()) if t == 1: unite(a, b) elif t == 2: X = find(a) add_root[X] += b else: print(query(a))