#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) { while (p[u] >= 0) u = p[u]; return 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) { int r = s[u]; while (p[u] >= 0) u = p[u], r += s[u]; return r; } 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; }