class UnionFind: def __init__(self, n=1): self.parent = [i for i in range(n)] self.rank = [0] * n self.value = [0] * n def find(self, x): if self.parent[x] == x: return x, 0 else: p, v = self.find(self.parent[x]) self.parent[x] = p self.value[x] += v return self.parent[x], self.value[x] def union(self, x, y): x, _ = self.find(x) y, _ = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.parent[y] = x self.value[y] -= self.value[x] def is_same(self, x, y): return self.find(x)[0] == self.find(y)[0] def add(self, x, v): p, _ = self.find(x) self.value[p] += v def get_value(self, x): p, _ = self.find(x) return self.value[x] + self.value[p]*(p!=x) N, Q = map(int, input().split()) uf = UnionFind(N) for _ in range(Q): t, a, b = map(int, input().split()) a -= 1 if t == 1: b -= 1 uf.union(a, b) elif t == 2: uf.add(a, b) else: v = uf.get_value(a) print(v)