#include <bits/stdc++.h>
const int N = 200005, mu = 1e9 + 7;
int in[N], out[N], idn, q[N], opt[N], f[N], tr[N << 2], tag[N << 2], w[N], d[N];
int Q, id[N], n, inv[N];
std::vector<int> e[N];
void dfs(int x) {
  in[x] = ++idn;
  for (int i : e[x]) dfs(i);
  out[x] = idn;
}
int ksm(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = x * 1ll * x % mu)
    if (y & 1) ans = ans * 1ll * x % mu;
  return ans;
}
void puttag(int x, int v) {
  tag[x] = tag[x] * 1ll * v % mu;
  tr[x] = tr[x] * 1ll * v % mu;
}
void pushdown(int x) {
  int t = tag[x];
  if (t != 1) {
    puttag(x << 1, t);
    puttag(x << 1 | 1, t);
    tag[x] = 1;
  }
}
void push_up(int x) { tr[x] = (tr[x << 1] + tr[x << 1 | 1]) % mu; }
void modify(int k, int L, int R, int l, int r, int v) {
  if (L == l && R == r) {
    puttag(k, v);
    return;
  }
  pushdown(k);
  int mid = (L + R) >> 1;
  if (r <= mid)
    modify(k << 1, L, mid, l, r, v);
  else if (l > mid)
    modify(k << 1 | 1, mid + 1, R, l, r, v);
  else {
    modify(k << 1, L, mid, l, mid, v);
    modify(k << 1 | 1, mid + 1, R, mid + 1, r, v);
  }
  push_up(k);
}
int query(int k, int L, int R, int l, int r) {
  if (L == l && R == r) return tr[k];
  pushdown(k);
  int mid = (L + R) >> 1;
  if (r <= mid) return query(k << 1, L, mid, l, r);
  if (l > mid) return query(k << 1 | 1, mid + 1, R, l, r);
  return (query(k << 1, L, mid, l, mid) +
          query(k << 1 | 1, mid + 1, R, mid + 1, r)) %
         mu;
}
void upd(int k, int l, int r, int x, int v) {
  if (l == r) {
    tr[k] = tag[k] * 1ll * v % mu;
    return;
  }
  pushdown(k);
  int mid = (l + r) >> 1;
  if (x <= mid)
    upd(k << 1, l, mid, x, v);
  else
    upd(k << 1 | 1, mid + 1, r, x, v);
  push_up(k);
}
int main() {
  scanf("%d%d", &w[1], &Q);
  n = 1;
  for (int i = 1; i <= Q; i++) {
    scanf("%d", &opt[i]);
    if (opt[i] == 1) {
      ++n;
      scanf("%d%d", &f[n], &w[n]);
      e[f[n]].push_back(n);
      id[i] = n;
    } else
      scanf("%d", &q[i]);
  }
  dfs(1);
  inv[0] = 1, inv[1] = 1;
  for (int i = 1; i <= n * 4; i++) tag[i] = 1;
  for (int i = 2; i <= n; i++) inv[i] = 1ll * (mu - mu / i) * inv[mu % i] % mu;
  d[1] = 1;
  upd(1, 1, n, 1, w[1]);
  for (int i = 1; i <= Q; i++) {
    if (opt[i] == 1) {
      int x = id[i], fa = f[x];
      d[x] = 1;
      upd(1, 1, n, in[x], w[x]);
      modify(1, 1, n, in[fa], out[fa], 1ll * inv[d[fa]] * (d[fa] + 1) % mu);
      d[fa]++;
    } else {
      int x = q[i];
      int ans = query(1, 1, n, in[x], out[x]);
      if (f[x])
        ans = ans * 1ll * ksm(query(1, 1, n, in[f[x]], in[f[x]]), mu - 2) % mu *
              w[f[x]] % mu;
      printf("%d\n", ans);
    }
  }
}
