#include #include #include #include #include #include #include using namespace std; using ll = long long; struct UnionFind { UnionFind(int n) : p(n, -1), s(n, 0) {} int root(int u) { return p[u] < 0 ? u : root(p[u]); } int size(int u) { return -p[root(u)]; } bool same(int u, int v) { return root(u) == root(v); } void unite(int u, int v) { u = root(u); v = root(v); if (u == v) return; if (p[u] > p[v]) swap(u, v); p[u] += p[v]; p[v] = u; s[v] -= s[u]; } void add(int u, int a) { s[root(u)] += a; } int sum(int u) { return p[u] < 0 ? s[u] : s[u] + sum(p[u]); } vector p, s; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; UnionFind uf(n); while (q--) { int t, a, b; cin >> t >> a >> b; a--; if (t == 1) { b--; if (!uf.same(a, b)) uf.unite(a, b); } else if (t == 2) { uf.add(a, b); } else { cout << uf.sum(a) << '\n'; } } return 0; }