import sys input = sys.stdin.readline class Unionfind: def __init__(self, n): self.par = [-1]*n self.rank = [1]*n self.comp = [[i] for i in range(n)] self.rp = [0]*n self.vp = [0]*n def root(self, x): r = x while not self.par[r]<0: r = self.par[r] t = x while t!=r: tmp = t t = self.par[t] self.par[tmp] = r return r def unite(self, x, y): rx = self.root(x) ry = self.root(y) if rx==ry: return if self.rank[rx]<=self.rank[ry]: self.par[ry] += self.par[rx] self.par[rx] = ry if self.rank[rx]==self.rank[ry]: self.rank[ry] += 1 for v in self.comp[rx]: self.vp[v] = self.rp[rx]+self.vp[v]-self.rp[ry] self.comp[ry].append(v) else: self.par[rx] += self.par[ry] self.par[ry] = rx for v in self.comp[ry]: self.vp[v] = self.rp[ry]+self.vp[v]-self.rp[rx] self.comp[rx].append(v) def is_same(self, x, y): return self.root(x)==self.root(y) def count(self, x): return -self.par[self.root(x)] def add(self, x, y): self.rp[self.root(x)] += y def query(self, x): return self.rp[self.root(x)]+self.vp[x] N, Q = map(int, input().split()) uf = Unionfind(N) 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: print(uf.query(A-1))