import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np class DJSet(): def __init__(self, n): self.upper = np.empty((n), int) self.weight = np.empty((n), int) for i in range(n): self.upper[i] = -1 self.weight[i] = 0 def equiv(self, x, y): return self.root(x) == self.root(y) def root(self, x): if self.upper[x] < 0: return x else: return self.root(self.upper[x]) def get_weight(self, x): if self.upper[x] < 0: return self.weight[x] else: return self.weight[x] + self.get_weight(self.upper[x]) def setUnion(self, x, y): x = self.root(x) y = self.root(y) if x == y: return if self.upper[x] < self.upper[y]: x ^= y y ^= x x ^= y self.upper[y] = self.upper[y] + self.upper[x] self.upper[x] = y self.weight[x] = self.weight[x] - self.weight[y] def add_weight(self, x, w): x = self.root(x) self.weight[x] = self.weight[x] + w def run(): N, Q = map(int, readline().split()) ds = DJSet(N) for q in range(Q): T, A, B = map(int, readline().split()) A = A - 1 if (T == 1): B = B - 1 if (ds.equiv(A, B)): continue ds.setUnion(A, B) elif (T == 2): ds.add_weight(A, B) elif (T == 3): print(ds.get_weight(A)) run()