#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
vector<long long> v[200005];
long long l[200005], r[200005], b[200005], t[200005], fa[200005], a[200005],
    cnt, mod = 1e9 + 7, siz[200005];
void dfs(long long x, long long y) {
  l[x] = ++cnt;
  for (auto u : v[x])
    if (u != y) {
      dfs(u, x);
    }
  r[x] = cnt;
}
long long tag[1 << 19], val[1 << 19], mul[1 << 19];
void build(long long x, long long l, long long r) {
  tag[x] = 1;
  mul[x] = 1;
  if (l == r) return;
  long long mid = (l + r) >> 1;
  build((x << 1), l, mid);
  build(((x << 1) | 1), mid + 1, r);
}
void pushdown(long long x, long long l, long long r) {
  if (l != r) {
    tag[(x << 1)] = tag[(x << 1)] * tag[x] % mod;
    tag[((x << 1) | 1)] = tag[((x << 1) | 1)] * tag[x] % mod;
    mul[(x << 1)] = mul[(x << 1)] * tag[x] % mod;
    mul[((x << 1) | 1)] = mul[((x << 1) | 1)] * tag[x] % mod;
    val[(x << 1)] = val[(x << 1)] * tag[x] % mod;
    val[((x << 1) | 1)] = val[((x << 1) | 1)] * tag[x] % mod;
  }
  tag[x] = 1;
}
void update(long long x, long long l, long long r, long long tl, long long tr,
            long long muti) {
  pushdown(x, l, r);
  if (l >= tl && r <= tr) {
    tag[x] = tag[x] * muti % mod;
    mul[x] = mul[x] * muti % mod;
    val[x] = val[x] * muti % mod;
    return;
  }
  if (l > tr || tl > r) return;
  long long mid = (l + r) >> 1;
  update((x << 1), l, mid, tl, tr, muti);
  update(((x << 1) | 1), mid + 1, r, tl, tr, muti);
  val[x] = (val[(x << 1)] + val[((x << 1) | 1)]) % mod;
}
void update1(long long x, long long l, long long r, long long it,
             long long add) {
  pushdown(x, l, r);
  if (l == r) {
    val[x] = (val[x] + add * mul[x]) % mod;
    return;
  }
  long long mid = (l + r) >> 1;
  if (mid >= it)
    update1((x << 1), l, mid, it, add);
  else
    update1(((x << 1) | 1), mid + 1, r, it, add);
  val[x] = (val[(x << 1)] + val[((x << 1) | 1)]) % mod;
}
long long get(long long x, long long l, long long r, long long it) {
  pushdown(x, l, r);
  if (l == r) return mul[x];
  long long mid = (l + r) >> 1;
  if (mid >= it) {
    return get((x << 1), l, mid, it);
  } else
    return get(((x << 1) | 1), mid + 1, r, it);
}
long long getval(long long x, long long l, long long r, long long tl,
                 long long tr) {
  pushdown(x, l, r);
  if (l >= tl && r <= tr) return val[x];
  if (l > tr || tl > r) return 0;
  long long mid = (l + r) >> 1;
  return (getval((x << 1), l, mid, tl, tr) +
          getval(((x << 1) | 1), mid + 1, r, tl, tr)) %
         mod;
}
long long __pow(long long x, long long y) {
  if (!y) return 1;
  long long t = __pow(x, y / 2);
  if (y & 1) {
    return t * t % mod * x % mod;
  } else
    return t * t % mod;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, q;
  n = 1;
  cin >> a[1] >> q;
  for (long long i = 1; i <= q; i++) {
    cin >> t[i];
    if (t[i] == 1) {
      long long x, y;
      cin >> x >> y;
      fa[++n] = x;
      v[x].emplace_back(n);
      a[n] = y;
    } else
      cin >> b[i];
  }
  dfs(1, -1);
  build(1, 1, n);
  long long tn = 1;
  update1(1, 1, n, 1, a[1]);
  for (long long i = 1; i <= n; i++) siz[i] = 1;
  for (long long i = 1; i <= q; i++) {
    if (t[i] == 1) {
      tn++;
      update(1, 1, n, l[fa[tn]], r[fa[tn]],
             __pow(siz[fa[tn]], mod - 2) * (++siz[fa[tn]]) % mod);
      update1(1, 1, n, l[tn], a[tn]);
    } else {
      cout << getval(1, 1, n, l[b[i]], r[b[i]]) *
                  (b[i] == 1 ? 1 : __pow(get(1, 1, n, l[fa[b[i]]]), mod - 2)) %
                  mod
           << '\n';
    }
  }
  return 0;
}
