#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int n, q;
int pre[N], to[N], head[N], wcnt;
int fa[N], val[N], id[N], size[N], deg[N], idcnt;
int qopt[N], qu[N];
int seg[N << 2], mark[N << 2];
int c[N];
inline int qmod(int x) { return (x >= MOD) ? (x - MOD) : x; }
inline int qpow(long long b, int p, int mod = MOD) {
  int res = 1;
  while (p) {
    if (p & 1) res = res * b % mod;
    b = b * b % mod;
    p >>= 1;
  }
  return res;
}
inline void add(int l, int r, int x) {
  for (; l <= n; l += l & -l) c[l] = 1LL * c[l] * x % MOD;
  for (r++, x = qpow(x, MOD - 2); r <= n; r += r & -r)
    c[r] = 1LL * c[r] * x % MOD;
}
inline int query(int p) {
  int res = 1;
  for (; p; p ^= p & -p) res = 1LL * res * c[p] % MOD;
  return res;
}
inline void addedge(int u, int v) {
  pre[++wcnt] = head[u];
  head[u] = wcnt;
  to[wcnt] = v;
}
void dfs(int u) {
  int i;
  id[u] = ++idcnt;
  size[u] = 1;
  for (i = head[u]; i; i = pre[i]) {
    dfs(to[i]);
    size[u] += size[to[i]];
  }
}
inline void mulnode(int p, int x) {
  seg[p] = 1LL * seg[p] * x % MOD;
  mark[p] = 1LL * mark[p] * x % MOD;
}
inline void down(int p) {
  if (mark[p] ^ 1) {
    mulnode((p << 1), mark[p]);
    mulnode((p << 1 | 1), mark[p]);
    mark[p] = 1;
  }
}
void build(int p, int l, int r) {
  mark[p] = 1;
  if (l ^ r) {
    build((p << 1), l, ((l + r) >> 1));
    build((p << 1 | 1), ((l + r) >> 1) + 1, r);
  }
}
void ins(int p, int l, int r, int a, int x) {
  if (l == r) {
    seg[p] = x;
    return;
  }
  down(p);
  if (a <= ((l + r) >> 1))
    ins((p << 1), l, ((l + r) >> 1), a, x);
  else
    ins((p << 1 | 1), ((l + r) >> 1) + 1, r, a, x);
  seg[p] = qmod(seg[(p << 1)] + seg[(p << 1 | 1)]);
}
void mul(int p, int l, int r, int a, int b, int x) {
  if (a <= l and r <= b) {
    mulnode(p, x);
    return;
  }
  down(p);
  if (a <= ((l + r) >> 1)) mul((p << 1), l, ((l + r) >> 1), a, b, x);
  if (b > ((l + r) >> 1)) mul((p << 1 | 1), ((l + r) >> 1) + 1, r, a, b, x);
  seg[p] = qmod(seg[(p << 1)] + seg[(p << 1 | 1)]);
}
int query(int p, int l, int r, int a, int b) {
  if (a <= l and r <= b) return seg[p];
  down(p);
  if (a <= ((l + r) >> 1) and b > ((l + r) >> 1))
    return qmod(query((p << 1), l, ((l + r) >> 1), a, b) +
                query((p << 1 | 1), ((l + r) >> 1) + 1, r, a, b));
  else if (a <= ((l + r) >> 1))
    return query((p << 1), l, ((l + r) >> 1), a, b);
  else
    return query((p << 1 | 1), ((l + r) >> 1) + 1, r, a, b);
}
int main() {
  int i, u;
  scanf("%d %d", &val[1], &q);
  n = 1;
  for (i = int(1); i <= int(q); i++) {
    scanf("%d", &qopt[i]);
    if (qopt[i] == 1) {
      qu[i] = ++n;
      scanf("%d %d", &fa[n], &val[n]);
      addedge(fa[n], n);
    } else
      scanf("%d", &qu[i]);
  }
  dfs(1);
  build(1, 1, n);
  ins(1, 1, n, 1, val[1]);
  for (i = int(1); i <= int(n); i++) c[i] = deg[i] = 1;
  for (i = int(1); i <= int(q); i++) {
    u = qu[i];
    if (qopt[i] == 1) {
      mul(1, 1, n, id[fa[u]], id[fa[u]] + size[fa[u]] - 1,
          qpow(deg[fa[u]], MOD - 2));
      add(id[fa[u]], id[fa[u]] + size[fa[u]] - 1, qpow(deg[fa[u]], MOD - 2));
      deg[fa[u]]++;
      mul(1, 1, n, id[fa[u]], id[fa[u]] + size[fa[u]] - 1, deg[fa[u]]);
      add(id[fa[u]], id[fa[u]] + size[fa[u]] - 1, deg[fa[u]]);
      ins(1, 1, n, id[u], 1LL * query(id[u]) * val[u] % MOD);
    } else
      printf("%lld\n", 1LL * query(1, 1, n, id[u], id[u] + size[u] - 1) *
                           qpow(query(id[fa[u]]), MOD - 2) % MOD);
  }
  return 0;
}
