class UnionFind(): def __init__(self, n): self.n = n self.parents = [i for i in range(n)] self.added = [0 for _ in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): root = x while self.parents[root] != root: root = self.parents[root] return root def unite(self, x, y): xroot = self.find(x) yroot = self.find(y) if xroot == yroot: return if self.size[xroot] <= self.size[yroot]: self.parents[xroot] = yroot self.added[xroot] -= self.added[yroot] self.size[yroot] += self.size[xroot] else: self.parents[yroot] = xroot self.added[yroot] -= self.added[xroot] self.size[xroot] += self.size[yroot] def add(self, x, a): self.added[self.find(x)] += a def get(self, x): res = 0 root = x while self.parents[root] != root: res += self.added[root] root = self.parents[root] res += self.added[root] return res import sys input = sys.stdin.readline N, Q = map(int, input().split()) uf = UnionFind(N) res = [] for _ in range(Q): t, a, b = map(int, input().split()) if t == 1: uf.unite(a - 1, b - 1) elif t == 2: uf.add(a - 1, b) else: res.append(uf.get(a - 1)) print('\n'.join(map(str, res)))