#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e9 + 7;
int head[200005], v[200005], suc[200005], en;
void addedge(int iu, int iv) {
  en++;
  suc[en] = head[iu];
  v[en] = iv;
  head[iu] = en;
}
int in[200005], out[200005], dfn_cnt;
void dfs(int s) {
  in[s] = ++dfn_cnt;
  for (int i = head[s]; i; i = suc[i]) {
    dfs(v[i]);
  }
  out[s] = dfn_cnt;
}
int qpow(int x, int y) {
  int rt = 1;
  y = (y % (M - 1) + (M - 1)) % (M - 1);
  while (y) {
    if (y & 1) rt = (long long)rt * x % M;
    x = (long long)x * x % M;
    y >>= 1;
  }
  return rt;
}
int c[200005 * 8], tag[200005 * 8], qs, qt, qx;
void multiply(int at, int x) {
  if (tag[at] == 0)
    tag[at] = x;
  else
    tag[at] = (long long)tag[at] * x % M;
  c[at] = (long long)c[at] * x % M;
}
void pushdown(int at) {
  if (tag[at] == 0) return;
  multiply(at * 2, tag[at]);
  multiply(at * 2 + 1, tag[at]);
  tag[at] = 0;
}
void update(int f, int r, int at) {
  if (f == r) {
    c[at] = qx;
    return;
  }
  pushdown(at);
  int mid = (f + r) >> 1;
  if (qs <= mid)
    update(f, mid, at * 2);
  else
    update(mid + 1, r, at * 2 + 1);
  c[at] = (c[at * 2] + c[at * 2 + 1]) % M;
}
void change(int f, int r, int at) {
  if (qs <= f && r <= qt) {
    multiply(at, qx);
    return;
  }
  pushdown(at);
  int mid = (f + r) >> 1;
  if (qs <= mid) change(f, mid, at * 2);
  if (qt > mid) change(mid + 1, r, at * 2 + 1);
  c[at] = (c[at * 2] + c[at * 2 + 1]) % M;
}
void query(int f, int r, int at) {
  if (qs <= f && r <= qt) {
    qx = (qx + c[at]) % M;
    return;
  }
  pushdown(at);
  int mid = (f + r) >> 1;
  if (qs <= mid) query(f, mid, at * 2);
  if (qt > mid) query(mid + 1, r, at * 2 + 1);
}
int ord[200005], p[200005], w[200005], d[200005], pson[200005];
int main() {
  int i, j, k;
  int n, m;
  scanf("%d%d", w + 1, &m);
  j = 2;
  for (i = 1; i <= m; i++) {
    scanf("%d", ord + i);
    if (ord[i] == 1) {
      scanf("%d%d", p + i, w + j);
      addedge(p[i], j);
      pson[i] = j++;
    } else {
      scanf("%d", p + i);
    }
  }
  n = j - 1;
  dfs(1);
  qs = 1;
  qx = w[1];
  update(1, n, 1);
  for (i = 1; i <= m; i++) {
    int x = p[i], y = pson[i];
    if (ord[i] == 1) {
      qs = qt = in[x];
      qx = 0;
      query(1, n, 1);
      qs = in[y];
      qx = (long long)qx * qpow(w[x], -1) % M * w[y] % M;
      update(1, n, 1);
      qs = in[x];
      qt = out[x];
      qx = (long long)(d[x] + 2) * qpow(d[x] + 1, -1) % M;
      change(1, n, 1);
      d[x]++;
    } else {
      qs = qt = in[x];
      qx = 0;
      query(1, n, 1);
      int tmp = (long long)qpow(qx, -1) * w[x] % M;
      qs = in[x];
      qt = out[x];
      qx = 0;
      query(1, n, 1);
      tmp = (long long)tmp * qx % M;
      tmp = (long long)tmp * (d[x] + 1) % M;
      printf("%d\n", tmp);
    }
  }
  return 0;
}
