#include using namespace std; #define fi first #define se second #define pb push_back using vi = vector ; using ll = long long; using vl = vector ; using pii = pair ; const ll mod = 998244353; //~ const ll mod = 1e9 + 7; ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a; for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; } const int N = 5e5 + 11; int p[N], s[N]; pii find(int x) { if(p[x] == x) return {x, s[x]}; int y = p[x]; auto [root, sum] = find(y); p[x] = root; s[x] = sum + s[x] - s[root]; return {root, s[root] + s[x]}; } int main() { ios::sync_with_stdio(0); int n, q; cin >> n >> q; iota(p, p + n + 1, 0); while(q --) { int t, a, b; cin >> t >> a >> b; if(t == 1) { int u = find(a).fi, v = find(b).fi; s[u] -= s[v]; p[u] = v; } else if(t == 2) { s[find(a).fi] += b; } else { cout << find(a).se << '\n'; } } }