#include <bits/stdc++.h>
using namespace std;
struct data {
  long long tag, sum, dg;
} t[200500 * 4];
struct edge {
  int obj, pre;
} e[200500 * 2];
int fa[200500], head[200500], st[200500], ed[200500], q[200500][2];
long long val[200500], deg[200500];
int n, m, tot, idx;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void insert(int x, int y) {
  e[++tot].obj = y;
  e[tot].pre = head[x];
  head[x] = tot;
}
long long Pow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % 1000000007;
    x = x * x % 1000000007;
    y /= 2;
  }
  return ans;
}
void dfs(int u) {
  st[u] = ++idx;
  for (int j = head[u]; j; j = e[j].pre) {
    int v = e[j].obj;
    dfs(v);
  }
  ed[u] = idx;
}
void get(int i, long long tag) {
  t[i].sum = (t[i].sum * tag) % 1000000007;
  t[i].dg = (t[i].dg * tag) % 1000000007;
  t[i].tag = (t[i].tag * tag) % 1000000007;
}
void Down(int i) {
  if (t[i].tag != 1) {
    long long tag = t[i].tag;
    get(i * 2, tag);
    get(i * 2 + 1, tag);
    t[i].tag = 1;
  }
}
void up(int i) {
  t[i].dg = (t[i * 2].dg + t[i * 2 + 1].dg) % 1000000007;
  t[i].sum = (t[i * 2].sum + t[i * 2 + 1].sum) % 1000000007;
}
void add(int i, int l, int r, int x, long long c, long long v) {
  if (l == r) {
    t[i].tag = 1;
    t[i].sum = (t[i].sum + c * v % 1000000007) % 1000000007;
    t[i].dg = (t[i].dg + c) % 1000000007;
    return;
  }
  Down(i);
  int mid = (l + r) / 2;
  if (x <= mid)
    add(i * 2, l, mid, x, c, v);
  else
    add(i * 2 + 1, mid + 1, r, x, c, v);
  up(i);
}
void mul(int i, int l, int r, int L, int R, long long c) {
  if (L <= l && r <= R) {
    get(i, c);
    return;
  }
  Down(i);
  int mid = (l + r) / 2;
  if (L <= mid) mul(i * 2, l, mid, L, R, c);
  if (R > mid) mul(i * 2 + 1, mid + 1, r, L, R, c);
  up(i);
}
long long ask(int i, int l, int r, int x) {
  if (l == r) return t[i].dg;
  Down(i);
  int mid = (l + r) / 2;
  if (x <= mid)
    return ask(i * 2, l, mid, x);
  else
    return ask(i * 2 + 1, mid + 1, r, x);
}
long long query(int i, int l, int r, int L, int R) {
  if (L <= l && r <= R) return t[i].sum;
  Down(i);
  int mid = (l + r) / 2;
  long long ans = 0;
  if (L <= mid) ans = (ans + query(i * 2, l, mid, L, R)) % 1000000007;
  if (R > mid) ans = (ans + query(i * 2 + 1, mid + 1, r, L, R) % 1000000007);
  return ans;
}
int main() {
  val[1] = read();
  m = read();
  n = 1;
  for (int i = 1; i <= m; i++) {
    q[i][0] = read();
    if (q[i][0] == 1) {
      q[i][1] = ++n;
      fa[n] = read();
      val[n] = read();
      insert(fa[n], n);
    } else
      q[i][1] = read();
  }
  dfs(1);
  for (int i = 1; i <= n; i++) deg[i] = 1;
  add(1, 1, n, 1, 1, val[1]);
  for (int i = 1; i <= m; i++) {
    if (q[i][0] == 1) {
      int v = q[i][1], u = fa[v];
      mul(1, 1, n, st[u], ed[u], 1 + Pow(deg[u], 1000000007 - 2));
      deg[u]++;
      long long pd = ask(1, 1, n, st[u]);
      add(1, 1, n, st[v], pd, val[v]);
    } else {
      int v = q[i][1], u = fa[v];
      long long ans = query(1, 1, n, st[v], ed[v]);
      if (u)
        ans = (ans * Pow(ask(1, 1, n, st[u]), 1000000007 - 2)) % 1000000007;
      printf("%lld\n", ans);
    }
  }
  return 0;
}
