#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 200010, mod = 1000000007;
struct edge {
  int v, nxt;
} e[N << 1];
int head[N], cnt, n, m, x, y, z, siz[N], fa[N], dep[N], son[N], seg[N], rev[N],
    top[N], d[N << 2], f[N << 2], sum[N << 2], ans1, ans2;
struct node {
  int x, y, opt;
} a[N];
inline int fpow(int x, int p) {
  int ans = 1;
  for (; p; p >>= 1, x = 1ll * x * x % mod)
    if (p & 1) ans = 1ll * ans * x % mod;
  return ans;
}
inline void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
inline void dfs1(int u, int F) {
  dep[u] = dep[F] + 1;
  siz[u] = 1;
  fa[u] = F;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == F) continue;
    dfs1(v, u);
    siz[u] += siz[v];
    if (siz[v] > siz[son[u]]) son[u] = v;
  }
}
inline void dfs2(int u, int F) {
  seg[u] = ++seg[0];
  rev[seg[0]] = u;
  top[u] = F;
  if (!son[u]) return;
  dfs2(son[u], F);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == F || v == son[u]) continue;
    dfs2(v, v);
  }
}
inline void pushup(int p) { d[p] = 1ll * d[p << 1] * d[p << 1 | 1] % mod; }
inline void pushdown(int p) {
  if (f[p]) {
    int ls = p << 1, rs = p << 1 | 1;
    f[rs] = (f[rs] + f[p]) % mod;
    f[ls] = (f[ls] + 1ll * f[p] * d[rs] % mod) % mod;
    f[p] = 0;
  }
}
inline void change(int p, int l, int r, int x, int y) {
  if (l == r) {
    d[p] = (d[p] + 1) % mod;
    sum[p] = (sum[p] + y) % mod;
    return;
  }
  int mid = l + r >> 1, ls = p << 1, rs = p << 1 | 1;
  pushdown(p);
  if (x <= mid)
    change(ls, l, mid, x, y);
  else
    change(rs, mid + 1, r, x, y);
  pushup(p);
}
inline void query(int p, int l, int r, int x) {
  if (l == r) {
    ans1 = d[p];
    ans2 = (sum[p] + f[p]) % mod;
    return;
  }
  int mid = l + r >> 1, ls = p << 1, rs = p << 1 | 1;
  pushdown(p);
  if (x <= mid)
    query(ls, l, mid, x);
  else
    query(rs, mid + 1, r, x);
}
inline int Query(int p, int l, int r, int x, int y, int z) {
  if (x <= l && r <= y) {
    f[p] = (f[p] + z) % mod;
    return d[p];
  }
  int mid = l + r >> 1, ls = p << 1, rs = p << 1 | 1;
  pushdown(p);
  int ans = 1;
  if (y > mid) ans = 1ll * ans * Query(rs, mid + 1, r, x, y, z) % mod;
  if (x <= mid)
    ans = 1ll * ans * Query(ls, l, mid, x, y, 1ll * z * ans % mod) % mod;
  return ans;
}
inline void mian() {
  a[1].y = read();
  m = read();
  n = 1;
  for (int i = 1; i <= m; ++i) {
    a[i].opt = read();
    a[i].x = read();
    if (a[i].opt == 1) {
      ++n;
      a[n].y = read();
      add(a[i].x, n);
      a[i].x = n;
    }
  }
  dfs1(1, 0);
  dfs2(1, 1);
  change(1, 1, n, seg[1], a[1].y);
  for (int i = 1; i <= m; ++i) {
    if (a[i].opt == 1) {
      int p = a[i].x, cur = 1, num;
      change(1, 1, n, seg[p], a[p].y);
      ans1 = ans2 = 0;
      query(1, 1, n, seg[fa[p]]);
      change(1, 1, n, seg[fa[p]], a[p].y);
      num = ((1ll * ans1 * a[p].y % mod + ans2) % mod + a[p].y) % mod;
      for (int x = fa[fa[p]]; x; x = fa[top[x]])
        cur = 1ll * cur *
              Query(1, 1, n, seg[top[x]], seg[x], 1ll * num * cur % mod) % mod;
    } else {
      ans1 = ans2 = 0;
      query(1, 1, n, seg[a[i].x]);
      printf("%d\n", 1ll * ans1 * ans2 % mod);
    }
  }
}
int main() {
  int qwq = 1;
  while (qwq--) mian();
  return 0;
}
