#include #include #include #include #include #include #include using namespace std; typedef long long ll; int N, Q; int par[500000]; int dat[500000]; int root(int v){ return par[v] == v ? v : root(par[v]); } int size(int v){ int ans = 1; while(v != par[v]){ ans++; v = par[v]; } return ans; } int calc(int v){ int ans = dat[v]; while(v != par[v]){ v = par[v]; ans += dat[v]; } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N >> Q; for(int i = 0; i < N; i++){ par[i] = i; } for(int i = 0; i < Q; i++){ int t, a, b; cin >> t >> a >> b; if(t == 1){ a--; b--; int ra = root(a), rb = root(b); if(ra != rb){ if(size(a) < size(b)) swap(a, b); par[ra] = rb; dat[ra] -= dat[rb]; } }else if(t == 2) { a--; int r = root(a); dat[r] += b; }else{ a--; cout << calc(a) << endl; } } }