import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["n", "parent", "height", "size", "data"] def __init__(self, n): self.n = n self.parent = [i for i in range(n)] self.height = [1] * n self.size = [1] * n self.data = [0] * n def find(self, x): if self.parent[x] == x: return x else: new_parent = self.find(self.parent[x]) if new_parent != self.parent[x]: self.data[x] += self.data[self.parent[x]] self.parent[x] = new_parent return self.parent[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.height[x] < self.height[y]: self.parent[x] = y self.size[y] += self.size[x] self.data[x] -= self.data[y] else: self.parent[y] = x self.size[x] += self.size[y] self.data[y] -= self.data[x] if self.height[x] == self.height[y]: self.height[x] += 1 def add(self, x, b): self.data[self.find(x)] += b def get(self, x): res = self.data[x] while x != self.parent[x]: x = self.parent[x] res += self.data[x] return res N, Q = map(int, input().split()) uf = UnionFind(N) for _ in range(Q): query = tuple(map(int, input().split())) if query[0] == 1: uf.unite(query[1] - 1, query[2] - 1) elif query[0] == 2: uf.add(query[1] - 1, query[2]) elif query[0] == 3: print(uf.get(query[1] - 1))