# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline class DSU: def __init__(self, n): self._n = n self.parent_or_size = [-1] * n self.member = [[i] for i in range(n)] def merge(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n x, y = self.leader(a), self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] for tmp in self.member[y]: self.member[x].append(tmp) self.parent_or_size[y] = x return x def same(self, a, b): assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self._n if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a): assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [self.leader(i) for i in range(self._n)] result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return [r for r in result if r != []] N,Q = map(int,input().split()) D = DSU(N) X = [0]*N for _ in range(Q): t,a,b = map(int,input().split()) if t==1: a -= 1 b -= 1 if D.same(a,b): continue la = D.leader(a) lb = D.leader(b) ga = D.member[la] gb = D.member[lb] D.merge(a,b) lp = D.leader(la) if lp==la: for y in gb: if y!=lb: X[y] = X[lb] + X[y] for y in gb: X[y] = X[y] - X[lp] else: for y in ga: if y!=la: X[y] = X[la] + X[y] for y in ga: X[y] = X[y] - X[lp] elif t==2: a -= 1 X[D.leader(a)] += b else: a -= 1 ans = X[a] if D.leader(a) != a: ans += X[D.leader(a)] print(ans)