def Find(x, par): if par[x] < 0: return x else: par[x] = Find(par[x], par) return par[x] def Unite(x, y, par, size, plus, child): x = Find(x, par) y = Find(y, par) if x != y: if size[x] < size[y]: x, y = y, x size[x] += size[y] par[y] = x sub = plus[y]-plus[x] plus[y] = 0 for k in child[y]: child[x].add(k) plus[k] += sub child[y] = set() def Same(x, y, par): return Find(x, par) == Find(y, par) def Size(x, par, size): return size[Find(x, par)] import sys input = sys.stdin.buffer.readline n, q = map(int, input().split()) par = [-1]*n size = [1]*n child = [{i} for i in range(n)] plus = [0]*n for i in range(q): t, a, b = map(int, input().split()) if t == 1: a, b = a-1, b-1 Unite(a, b, par, size, plus, child) elif t == 2: a -= 1 plus[Find(a, par)] += b else: a -= 1 if par[a] == -1: print(plus[a]) else: print(plus[a]+plus[Find(a, par)])