mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.val = [0] * (n+1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x self.val[y] -= self.val[x] else: self.root[y] += self.root[x] self.root[x] = y self.val[x] -= self.val[y] if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, Q = map(int, input().split()) UF = UnionFind(N+1) ans = [] ans_append = ans.append for _ in range(Q): t, a, b = map(int, input().split()) if t == 1: UF.unite(a, b) elif t == 2: x = UF.find_root(a) UF.val[x] += b else: tmp = 0 x = a while True: tmp += UF.val[x] x = UF.root[x] if x < 0: break ans.append(tmp) print(*ans, sep="\n") if __name__ == '__main__': main()