import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int q = sc.nextInt(); UnionFindTree uft = new UnionFindTree(n); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int type = sc.nextInt(); if (type == 1) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; uft.unite(a, b); } else if (type == 2) { int a = sc.nextInt() - 1; int b = sc.nextInt(); uft.add(a, b); } else { sb.append(uft.get(sc.nextInt() - 1)).append("\n"); sc.nextInt(); } } System.out.print(sb); } static class UnionFindTree { int[] parents; int[] points; public UnionFindTree(int size) { parents = new int[size]; points = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (parents[x] == x) { return x; } int point = getPoint(parents[x]); parents[x] = find(parents[x]); points[x] = points[x] + point - points[parents[x]]; return parents[x]; } public int getPoint(int x) { if (parents[x] == x) { return points[x]; } else { return getPoint(parents[x]) + points[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; } parents[xx] = yy; points[xx] -= points[yy]; } public void add(int x, int value) { points[find(x)] += value; } public int get(int x) { int xx = find(x); if (xx == x) { return points[x]; } else { return points[x] + points[xx]; } } public String toString() { return Arrays.toString(parents) + Arrays.toString(points); } } }