import sys input = sys.stdin.buffer.readline N, Q = map(int, input().split()) tmp = [0] * N num = [0] * N root = [[i] for i in range(N)] def find(x): if isinstance(root[x], list): return x res = find(root[x]) root[x] = res return res def merge(x, y): x = find(x) y = find(y) if x == y: return if len(root[x]) > len(root[y]): x, y = y, x tx = tmp[x] if tx: for i in root[x]: num[i] += tx tmp[x] = 0 ty = tmp[y] if ty: for i in root[y]: num[i] += ty tmp[y] = 0 root[y].extend(root[x]) root[x] = y ans = [] for _ in range(Q): t, a, b = map(int, input().split()) if t == 1: merge(a-1, b-1) elif t == 2: leader = find(a-1) tmp[leader] += b else: leader = find(a-1) ans.append(num[a-1] + tmp[leader]) print(*ans, sep="\n")