import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int q = Integer.parseInt(first[1]); UnionFindTree uft = new UnionFindTree(n); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { String[] line = br.readLine().split(" ", 3); int type = Integer.parseInt(line[0]); int a = Integer.parseInt(line[1]); int b = Integer.parseInt(line[2]); if (type == 1) { uft.unite(a - 1, b - 1); } else if (type == 2) { uft.add(a - 1, b); } else { sb.append(uft.get(a - 1)).append("\n"); } } System.out.print(sb); } static class UnionFindTree { int[] parents; int[] depth; int[] values; public UnionFindTree(int size) { parents = new int[size]; depth = new int[size]; values = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; depth[i] = 1; } } public int find(int x) { if (x == parents[x]) { return x; } else { int tmp = parents[x]; int ans = find(parents[x]); if (tmp != parents[tmp]) { values[x] += values[tmp]; } parents[x] = ans; return ans; } } public void add(int x, int y) { values[find(x)] += y; } public int get(int x) { if (x == parents[x]) { return values[x]; } else { return values[x] + get(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public void unite(int x, int y) { int xx = find(x); int yy = find(y); if (xx == yy) { return; } if (depth[xx] >= depth[yy]) { parents[yy] = xx; depth[xx] += depth[yy]; values[yy] -= values[xx]; } else { parents[xx] = yy; depth[yy] += depth[xx]; values[xx] -= values[yy]; } } } }