#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
inline void read(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
template <class blank>
inline void smin(blank &a, blank b) {
  a = min(a, b);
}
template <class blank>
inline void smax(blank &a, blank b) {
  a = max(a, b);
}
const long long maxn = 2e5 + 10;
const long long maxm = 1e6 + 10;
const long long maxlg = 21;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e18 + 10;
const long long SQ = 317;
long long v[maxn], father[maxn], tp[maxn],
    vertexcur = 1, cur = 0, start[maxn], finish[maxn], id[maxn],
    stree[4 * maxn], lazy[4 * maxn], deg[maxn];
vector<long long> g[maxn], Q;
inline void dfs(long long node) {
  start[node] = cur++;
  for (auto u : g[node]) dfs(u);
  finish[node] = cur - 1;
}
inline long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b % 2) ret = ret * a % mod;
    a = a * a % mod;
    b /= 2;
  }
  return ret;
}
inline void shift(long long p) {
  lazy[2 * p + 1] = lazy[2 * p + 1] * lazy[p] % mod;
  lazy[2 * p + 2] = lazy[2 * p + 2] * lazy[p] % mod;
  stree[2 * p + 1] = stree[2 * p + 1] * lazy[p] % mod;
  stree[2 * p + 2] = stree[2 * p + 2] * lazy[p] % mod;
  lazy[p] = 1;
}
inline long long get(long long ql, long long qr, long long p = 0,
                     long long l = 0, long long r = cur - 1) {
  if (l > qr || r < ql) return 0;
  if (l >= ql && r <= qr) return stree[p];
  long long mid = (l + r) >> 1;
  shift(p);
  return (get(ql, qr, 2 * p + 1, l, mid) + get(ql, qr, 2 * p + 2, mid + 1, r)) %
         mod;
}
inline void multiply(long long ql, long long qr, long long val, long long p = 0,
                     long long l = 0, long long r = cur - 1) {
  if (l > qr || r < ql || l > r) return;
  if (l >= ql && r <= qr) {
    lazy[p] = lazy[p] * val % mod;
    stree[p] = stree[p] * val % mod;
    return;
  }
  long long mid = (l + r) >> 1;
  shift(p);
  multiply(ql, qr, val, 2 * p + 1, l, mid),
      multiply(ql, qr, val, 2 * p + 2, mid + 1, r);
  stree[p] = (stree[2 * p + 1] + stree[2 * p + 2]) % mod;
}
inline void update(long long qx, long long val, long long p = 0,
                   long long l = 0, long long r = cur - 1) {
  if (l > qx || r < qx) return;
  if (l == r) {
    stree[p] = val;
    return;
  }
  long long mid = (l + r) >> 1;
  shift(p);
  update(qx, val, 2 * p + 1, l, mid);
  update(qx, val, 2 * p + 2, mid + 1, r);
  stree[p] = (stree[2 * p + 1] + stree[2 * p + 2]) % mod;
}
inline void add_vertex(long long node) {
  long long multiplyValue =
      (deg[father[node]] + 2) * power(deg[father[node]] + 1, mod - 2) % mod;
  if (node == 1) {
    update(0, v[node]);
    return;
  }
  deg[father[node]]++;
  multiply(start[father[node]], finish[father[node]], multiplyValue);
  long long contrib = get(start[father[node]], start[father[node]]) *
                      power(v[father[node]], mod - 2) % mod;
  update(start[node], contrib * v[node] % mod);
}
inline long long calc(long long node) {
  long long contrib =
      get(start[node], start[node]) * power(v[node], mod - 2) % mod;
  return get(start[node], finish[node]) * (deg[node] + 1) % mod *
         power(contrib, mod - 2) % mod;
}
int32_t main() {
  v[1] = in();
  long long q = in();
  memset(father, -1, sizeof father);
  fill(lazy, lazy + maxn, 1);
  for (long long i = 0; i < q; i++) {
    tp[i] = in();
    if (tp[i] == 1) {
      vertexcur++;
      father[vertexcur] = in();
      v[vertexcur] = in();
      g[father[vertexcur]].push_back(vertexcur);
      id[i] = vertexcur;
    } else
      Q.push_back(in());
  }
  dfs(1);
  add_vertex(1);
  long long Qcur = 0;
  for (long long i = 0; i < q; i++) {
    if (tp[i] == 1)
      add_vertex(id[i]);
    else
      cout << calc(Q[Qcur++]) << "\n";
  }
}
