#pragma gcc optimize("Ofast") #include using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, q; cin >> n >> q; vector p(n + 1, -1); vector sv(n + 1), dv(n + 1); vector> s(n + 1); for (int i = 1; i <= n; ++i) s[i].emplace_back(i); function find = [&](int x) { return p[x] < 0 ? x : p[x] = find(p[x]); }; function merge = [&](int x, int y) { if ((x = find(x)) == (y = find(y))) return; if (p[x] > p[y]) swap(x, y); p[x] += p[y]; p[y] = x; for (auto e : s[y]) { sv[e] += dv[y] - dv[x]; s[x].emplace_back(e); } s[y].clear(); }; while (q--) { int t, a, b; cin >> t >> a >> b; if (t == 1) { merge(a, b); } if (t == 2) { dv[find(a)] += b; } if (t == 3) { cout << sv[a] + dv[find(a)] << '\n'; } } }