import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N, Q = map(int, input().split()) query = tuple(tuple(map(int, input().split())) for _ in range(Q)) root = [-1] * N member = [[i] for i in range(N)] leader_val = [0] * N each_val = [0] * N def find(x): if root[x] < 0: return x root[x] = res = find(root[x]) return res def unite(x, y): x = find(x) y = find(y) if x == y: return # x:big, y:small if -root[x] < -root[y]: x, y = y, x xval = leader_val[x] yval = leader_val[y] leader_val[y] = 0 root[x] += root[y] root[y] = x while member[y]: i = member[y].pop() each_val[i] += yval - xval member[x].append(i) for t, a, b in query: if t == 1: unite(a - 1, b - 1) elif t == 2: x = find(a - 1) leader_val[x] += b else: x = find(a - 1) print(leader_val[x] + each_val[a-1])