#include #define rep(i,n) for (int i = 0; i < (n); ++i) #define rrep(i,n) for (int i = (n)-1; i >= 0; i--) #define rep2(i,s,n) for (int i = (s); i < (n); ++i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define eb emplace_back #define vi vector #define vvi vector> #define vl vector #define vvl vector> #define vd vector #define vs vector #define vc vector #define vb vector #define vp vector

using namespace std; using ll = long long; using P = pair; using LP = pair; template istream& operator>>(istream& is,vector& v) { for(T& t:v){is>>t;} return is; } template ostream& operator<<(ostream& os,const vector& v) { for(T t:v){os< inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} const int inf = 1001001001; const ll linf = 1001001001001001001; class unionfind { int n; vector par,rank,val; public: unionfind(int n):n(n),par(n,-1),rank(n,0),val(n,0) {} int root(int x) { if(par[x] < 0) return x; else return root(par[x]); } bool same(int x,int y) { return root(x) == root(y); }; bool merge(int x,int y) { x = root(x); y = root(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x,y); if(rank[x] == rank[y]) rank[x]++; par[x] += par[y]; par[y] = x; val[y] -= val[x]; return true; } int size(int x) { return -par[root(x)]; }; bool connected() { rep(i,n-1) if(!same(i,i+1)) return false; return true; } void add(int v,int x) { val[root(v)] += x; } int get(int v) { int ret = 0; while(true) { ret += val[v]; if(par[v] < 0) break; v = par[v]; } return ret; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n,q; cin >> n >> q; unionfind uf(n); rep(_,q) { int t,a,b; cin >> t >> a >> b; if(t == 1) { a--; b--; uf.merge(a,b); } else if(t == 2) { a--; uf.add(a,b); } else { a--; cout << uf.get(a) << "\n"; } } }