#include <bits/stdc++.h>   using namespace std;   const long long maxN = 2e5 + 7;   const long long segN = 8e5 + 7;   const long long moD = 1e9 + 7;   struct query {     long long t, x, y;   };   long long n;   long long st[maxN], fi[maxN], sum[segN], deg[maxN], mul[segN], laz[segN],       val[maxN];   vector<long long> chi[maxN];   vector<query> que;   long long wop(long long x, long long y) {     if (y == 0) return 1;     long long res = wop(x, y / 2);     return res * res % moD * (y % 2 == 1 ? x : 1) % moD;   }   long long dfs(long long v) {     fi[v] = st[v] + 1;     for (long long u : chi[v]) {       st[u] = fi[v];       fi[v] = dfs(u);     }     return fi[v];   }   void merge(long long x) { sum[x] = (sum[x << 1] + sum[x << 1 | 1]) % moD; }   void upd(long long x, long long val) {     sum[x] = sum[x] * val % moD;     mul[x] = mul[x] * val % moD;     laz[x] = laz[x] * val % moD;   }   void shift(long long x) {     upd(x << 1, laz[x]);     upd(x << 1 | 1, laz[x]);     laz[x] = 1;   }   void add(long long idx, long long val, long long x = 1, long long xl = 0,            long long xr = n) {     if (xr - xl == 1) {       sum[x] = (sum[x] + val) % moD;       return;     }     long long xm = (xl + xr) >> 1;     shift(x);     if (idx < xm)       add(idx, val, x << 1, xl, xm);     else       add(idx, val, x << 1 | 1, xm, xr);     merge(x);   }   void mult(long long ql, long long qr, long long qv, long long x = 1,             long long xl = 0, long long xr = n) {     if (xl >= qr || xr <= ql) return;     if (ql <= xl && qr >= xr) {       sum[x] = sum[x] * qv % moD;       laz[x] = laz[x] * qv % moD;       mul[x] = mul[x] * qv % moD;       return;     }     shift(x);     long long xm = (xl + xr) >> 1;     mult(ql, qr, qv, x << 1, xl, xm);     mult(ql, qr, qv, x << 1 | 1, xm, xr);     merge(x);   }   long long get_mul(long long idx, long long x = 1, long long xl = 0,                     long long xr = n) {     if (xr - xl == 1) return mul[x];     long long xm = (xl + xr) >> 1;     shift(x);     if (idx < xm) return get_mul(idx, x << 1, xl, xm);     return get_mul(idx, x << 1 | 1, xm, xr);   }   long long get_sum(long long ql, long long qr, long long x = 1, long long xl = 0,                     long long xr = n) {     if (xl >= qr || xr <= ql) return 0;     if (ql <= xl && qr >= xr) return sum[x];     long long xm = (xl + xr) >> 1;     shift(x);     long long res = 0;     res += get_sum(ql, qr, x << 1, xl, xm);     res += get_sum(ql, qr, x << 1 | 1, xm, xr);     return res % moD;   }   long long inv(long long x) { return wop(x, moD - 2); }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long q;     cin >> val[0] >> q;     que.resize(q);     for (long long i = 0; i < q; ++i) {       cin >> que[i].t >> que[i].x;       que[i].x--;       if (que[i].t == 1) {         n++;         cin >> que[i].y;         chi[que[i].x].push_back(n);         val[n] = que[i].y;       }     }     n++;     for (long long i = 0; i < segN; ++i) laz[i] = mul[i] = 1;     dfs(0);     mul[0] = deg[0] = 1;     add(st[0], val[0]);     long long c = 0;     for (long long i = 0; i < q; ++i) {       long long v = que[i].x;       if (que[i].t == 1) {         c++;         deg[c] = 1;         mult(st[v], fi[v], inv(deg[v]) * (deg[v] + 1) % moD);         deg[v]++;         add(st[c], val[c] * get_mul(st[c]) % moD);       } else         cout << get_sum(st[v], fi[v]) * inv(get_mul(st[v])) % moD * deg[v] % moD              <<   n ;     }   }   