#include using namespace std; typedef long long int ll; ll mod = 1000000007; ll r(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod; else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod; } int main() { ll n, q; scanf("%lld%lld", &n, &q); vector pa(n); for (int i = 0; i < n; i++) pa[i] = i; vector> oya(n, vector(1)); for (int i = 0; i < n; i++) oya[i][0] = i; vector sum(n, 0); for (int i = 0; i < q; i++) { int t, a, b; scanf("%d%d%d", &t, &a, &b); if (t == 1) { a--; b--; int na = oya[pa[a]].size(); int nb = oya[pa[b]].size(); if (pa[a] != pa[b]) { int p; if (na >= nb) { p = pa[b]; for (int x : oya[pa[b]]) { pa[x] = pa[a]; oya[pa[a]].push_back(x); } } else { p = pa[a]; for (int x : oya[pa[a]]) { pa[x] = pa[b]; oya[pa[b]].push_back(x); } } } } else if (t == 2) { a--; for (int x : oya[pa[a]]) { sum[x] += b; } } else if (t == 3) { a--; printf("%lld\n", sum[a]); } } }