#include "bits/stdc++.h" using namespace std; //#include "atcoder/all" //using namespace atcoder; #define int long long #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i) #define ALL(a) a.begin(), a.end() #define IN(a, x, b) (a <= x && x < b) templateistream&operator >>(istream&is,vector&vec){for(T&x:vec)is>>x;return is;} templateinline void out(T t){cout << t << "\n";} templateinline void out(T t,Ts... ts){cout << t << " ";out(ts...);} templateinline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;} templateinline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;} constexpr int INF = 1e18; signed main(){ int N, Q; cin >> N >> Q; vector ans; vector par(N), plus(N), val(N); vector>v(N); REP(i, N) { par[i] = i; v[i].emplace_back(i); } auto merge = [&](int A, int B) { while(v[A].size()) { auto now = v[A].back(); v[A].pop_back(); val[now] += plus[A] - plus[B]; par[now] = B; v[B].emplace_back(now); } plus[A] = 0; }; REP(_, Q) { int T, A, B; cin >> T >> A >> B; --A; if(T == 1) { --B; int parA = par[A]; int parB = par[B]; if(parA == parB) continue; if(v[parA].size() < v[parB].size()) merge(parA, parB); else merge(parB, parA); } else if(T == 2) { int parA = par[A]; plus[parA] += B; } else { int parA = par[A]; ans.emplace_back(val[A] + plus[parA]); } } for(auto e: ans) out(e); }