#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int tot, cnt;
int fir[N], size[N], fa[N], son[N], dep[N], top[N], id[N];
struct edge {
  int to;
  int nxt;
} e[N];
inline void add(int x, int y) {
  e[++tot].to = y;
  e[tot].nxt = fir[x];
  fir[x] = tot;
}
inline void dfs1(int p) {
  size[p] = 1;
  for (int i = fir[p]; i; i = e[i].nxt) {
    int q = e[i].to;
    fa[q] = p, dep[q] = dep[p] + 1;
    dfs1(q), size[p] += size[q];
    if (size[q] > size[son[p]]) son[p] = q;
  }
}
inline void dfs2(int p) {
  id[p] = ++cnt;
  if (son[p]) top[son[p]] = top[p], dfs2(son[p]);
  for (int i = fir[p]; i; i = e[i].nxt) {
    int q = e[i].to;
    if (q == son[p]) continue;
    top[q] = q, dfs2(q);
  }
}
int res1, res2;
struct tree {
  int sigma[N << 2], d[N << 2], tag[N << 2];
  inline void pushdown(int p) {
    if (tag[p]) {
      tag[p * 2 + 1] = (tag[p * 2 + 1] + tag[p]) % mod;
      tag[p * 2] = (tag[p * 2] + 1ll * tag[p] * d[p * 2 + 1]) % mod;
      tag[p] = 0;
    }
  }
  inline void query(int p, int l, int r, int pos) {
    if (l == r) {
      res1 = d[p], res2 = (sigma[p] + tag[p]) % mod;
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(p);
    if (pos <= mid)
      query(p * 2, l, mid, pos);
    else
      query(p * 2 + 1, mid + 1, r, pos);
  }
  inline void change1(int p, int l, int r, int pos, int c) {
    if (l == r) {
      d[p]++, sigma[p] = (sigma[p] + c) % mod;
      return;
    }
    int mid = (l + r) >> 1;
    pushdown(p);
    if (pos <= mid)
      change1(p * 2, l, mid, pos, c);
    else
      change1(p * 2 + 1, mid + 1, r, pos, c);
    d[p] = 1ll * d[p * 2] * d[p * 2 + 1] % mod;
  }
  inline int change2(int p, int l, int r, int ql, int qr, int c) {
    if (ql <= l && qr >= r) {
      tag[p] = (tag[p] + c) % mod;
      return d[p];
    }
    int mid = (l + r) >> 1, cur = 1;
    pushdown(p);
    if (qr > mid)
      cur = 1ll * cur * change2(p * 2 + 1, mid + 1, r, ql, qr, c) % mod;
    if (ql <= mid)
      cur =
          1ll * cur * change2(p * 2, l, mid, ql, qr, 1ll * c * cur % mod) % mod;
    return cur;
  }
} t;
int v[N], opt[N], node[N];
int main() {
  int T, n = 1;
  scanf("%d%d", &v[1], &T);
  for (int i = 1; i <= T; i++) {
    scanf("%d%d", &opt[i], &node[i]);
    if (opt[i] == 1) {
      n++;
      scanf("%d", &v[n]);
      add(node[i], n), node[i] = n;
    }
  }
  dep[1] = 1, dfs1(1);
  top[1] = 1, dfs2(1);
  t.change1(1, 1, n, id[1], v[1]);
  for (int i = 1; i <= T; i++) {
    if (opt[i] == 1) {
      int p = node[i], now = 1, val;
      t.change1(1, 1, n, id[p], v[p]);
      res1 = res2 = 0, t.query(1, 1, n, id[fa[p]]);
      t.change1(1, 1, n, id[fa[p]], v[p]);
      val = (1ll * res1 * v[p] + res2 + v[p]) % mod;
      for (int x = fa[fa[p]]; x; x = fa[top[x]])
        now = 1ll * now *
              t.change2(1, 1, n, id[top[x]], id[x], 1ll * val * now % mod) %
              mod;
    } else {
      res1 = res2 = 0, t.query(1, 1, n, id[node[i]]);
      printf("%d\n", 1ll * res1 * res2 % mod);
    }
  }
  return 0;
}
