#include <bits/stdc++.h>
using namespace std;
int n = 1, q, cnt, ver, Q[200010][4], in[200010], out[200010], v[200010],
    deg[200010], sum[200010 << 2], mul[200010 << 2], k[200010 << 2];
vector<int> G[200010];
inline void push_up(int o) {
  sum[o] = sum[o << 1] + sum[o << 1 | 1];
  if (sum[o] >= 1000000007) sum[o] -= 1000000007;
}
inline void push_down(int o) {
  if (mul[o] != 1) {
    sum[o << 1] = 1LL * sum[o << 1] * mul[o] % 1000000007;
    sum[o << 1 | 1] = 1LL * sum[o << 1 | 1] * mul[o] % 1000000007;
    k[o << 1] = 1LL * k[o << 1] * mul[o] % 1000000007;
    k[o << 1 | 1] = 1LL * k[o << 1 | 1] * mul[o] % 1000000007;
    mul[o << 1] = 1LL * mul[o << 1] * mul[o] % 1000000007;
    mul[o << 1 | 1] = 1LL * mul[o << 1 | 1] * mul[o] % 1000000007;
    mul[o] = 1;
  }
}
void build(int l, int r, int o) {
  mul[o] = 1;
  if (l == r) {
    if (l == 1)
      sum[o] = ver, k[o] = 1;
    else
      sum[o] = 0, k[o] = 0;
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, o << 1);
  build(mid + 1, r, o << 1 | 1);
  push_up(o);
}
void update(int L, int R, int val, int l, int r, int o) {
  if (R < l || r < L || R < L) return;
  if (L <= l && r <= R) {
    sum[o] = 1LL * sum[o] * val % 1000000007;
    k[o] = 1LL * k[o] * val % 1000000007;
    mul[o] = 1LL * mul[o] * val % 1000000007;
    return;
  }
  push_down(o);
  int mid = l + r >> 1;
  update(L, R, val, l, mid, o << 1);
  update(L, R, val, mid + 1, r, o << 1 | 1);
  push_up(o);
}
void change(int p, int val, int l, int r, int o) {
  if (l == r) {
    sum[o] = 1LL * val * v[p] % 1000000007;
    k[o] = val;
    mul[o] = 1;
    return;
  }
  push_down(o);
  int mid = l + r >> 1;
  if (p <= mid)
    change(p, val, l, mid, o << 1);
  else
    change(p, val, mid + 1, r, o << 1 | 1);
  push_up(o);
}
int query(int L, int R, int l, int r, int o) {
  if (R < l || r < L || R < L) return 0;
  if (L <= l && r <= R) return sum[o];
  push_down(o);
  int mid = l + r >> 1;
  return (query(L, R, l, mid, o << 1) + query(L, R, mid + 1, r, o << 1 | 1)) %
         1000000007;
}
int ask(int p, int l, int r, int o) {
  if (l == r) return k[o];
  push_down(o);
  int mid = l + r >> 1;
  if (p <= mid)
    return ask(p, l, mid, o << 1);
  else
    return ask(p, mid + 1, r, o << 1 | 1);
}
void dfs(int u) {
  in[u] = ++cnt;
  for (auto v : G[u]) dfs(v);
  out[u] = cnt;
}
int power(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % 1000000007;
    a = 1LL * a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d%d", &ver, &q);
  v[1] = ver;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &Q[i][0]);
    if (Q[i][0] == 1) {
      scanf("%d%d", &Q[i][1], &Q[i][3]);
      Q[i][2] = ++n;
      G[Q[i][1]].push_back(Q[i][2]);
    } else {
      scanf("%d", &Q[i][1]);
    }
  }
  dfs(1);
  for (int i = 1; i <= n; i++) deg[i] = 1;
  build(1, n, 1);
  for (int i = 1; i <= q; i++) {
    if (Q[i][0] == 1) {
      int fa = Q[i][1], u = Q[i][2];
      v[in[u]] = Q[i][3];
      update(in[fa], out[fa],
             1LL * (deg[fa] + 1) * power(deg[fa], 1000000007 - 2) % 1000000007,
             1, n, 1);
      deg[fa]++;
      change(in[u], ask(in[fa], 1, n, 1), 1, n, 1);
    } else {
      int u = Q[i][1], ans = query(in[u], out[u], 1, n, 1);
      ans = 1LL * ans * deg[u] % 1000000007;
      ans = 1LL * ans * power(ask(in[u], 1, n, 1), 1000000007 - 2) % 1000000007;
      printf("%d\n", ans);
    }
  }
  return 0;
}
