import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] dij = [(0, 1), (1, 0), (1, 1), (1, -1)] inf = 10**16 md = 998244353 # md = 10**9+7 class UnionFind: def __init__(self, n): self.table = [-1]*n self.mem = [[u] for u in range(n)] self.vv = [0]*n # cntはグループ数 self.cnt = n def root(self, u): stack = [] while self.table[u] >= 0: stack.append(u) u = self.table[u] for v in stack: self.table[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return su = -self.table[u] sv = -self.table[v] if su < sv: u, v = v, u self.table[u] = -su-sv self.table[v] = u diff = self.vv[v]-self.vv[u] self.vv[v] = 0 for m in self.mem[v]: self.vv[m] += diff self.mem[u] += self.mem[v] self.mem[v].clear() self.cnt -= 1 return def member(self, u): return self.mem[self.root(u)] # グループの要素数 def size(self, u): return -self.table[self.root(u)] def value(self, u): r = self.root(u) if r == u: return self.vv[r] return self.vv[r]+self.vv[u] def add(self, u, a): u = self.root(u) self.vv[u] += a n, q = LI() uf = UnionFind(n) for _ in range(q): t, a, b = LI() if t == 1: uf.merge(a-1, b-1) if t == 2: uf.add(a-1, b) if t == 3: print(uf.value(a-1))