import sys sys.setrecursionlimit(100000000) MOD = 10 ** 9 + 7 INF = 10 ** 15 class UnionFind(): def __init__(self,n): self.n = n self.parents = [-1]*n self.count = [0] * n self.lazy = [0]*n self.plus = [0]*n def find(self,x): #根を見つける、繋ぎ直す if self.parents[x] < 0: return x else: p = self.find(self.parents[x]) self.lazy[x] += self.lazy[self.parents[x]] self.lazy[x] += self.plus[self.parents[x]] self.parents[x] = p return p def unite(self,x,y): #x,yの含むグループを併合する x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x,y = y,x self.parents[x] += self.parents[y] self.lazy[y] = -self.count[x] self.plus[y] = self.count[y] self.parents[y] = x def same(self,x,y):#xとyが同じグループにいるか判定 return self.find(x) == self.find(y) def members(self,x):#xと同じグループのメンバーを列挙 root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def size(self,x):#xが属するグループのメンバーの数 return -self.parents[self.find(x)] def roots(self):#ufの根を列挙 return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self):#グループの数を数える return len(self.roots()) def all_group_members(self):#根:メンバの辞書を返す return {r: self.members(r) for r in self.roots()} def __str__(self):#print()での表示用 return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def add(self,x,b): x = self.find(x) self.count[x] += b def calc(self,x): if self.parents[x] < 0: return self.count[x] self.find(x) return self.lazy[x] + self.count[x] + self.count[self.parents[x]] def main(): N,Q = map(int,input().split()) uf = UnionFind(N) for _ in range(Q): t,a,b = map(int,input().split()) if t == 1: a -= 1 b -= 1 uf.unite(a,b) elif t == 2: a -= 1 uf.add(a,b) else: a -= 1 print(uf.calc(a)) if __name__ == '__main__': main()