#include int ri() { int n; scanf("%d", &n); return n; } struct QuickFind { std::vector parent; // -size if it's root std::vector > child; std::vector plus; QuickFind (int n) : parent(n, -1), child(n), plus(n) { for (int i = 0; i < n; i++) child[i].push_back(i); } int root(int i) { return parent[i] < 0 ? i : parent[i] = root(parent[i]); } void add_union(int i, int val) { plus[root(i)] += val; } int get(int i) { return parent[i] < 0 ? plus[i] : plus[i] + plus[root(i)]; } void unite(int i, int j) { i = root(i); j = root(j); if (i == j) return; if (parent[i] > parent[j]) std::swap(i, j); parent[i] += parent[j]; parent[j] = i; int sub = plus[j] - plus[i]; plus[j] = 0; for (auto k : child[j]) { child[i].push_back(k); plus[k] += sub; } child[j].clear(); } }; int main() { int n = ri(); int q = ri(); QuickFind uni(n); for (int i = 0; i < q; i++) { int t = ri(), a = ri() - 1, b = ri(); if (t == 1) uni.unite(a, b - 1); else if (t == 2) uni.add_union(a, b); else printf("%d\n", uni.get(a)); } return 0; }