#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int Mod = 1e9 + 7;
int n = 1, q;
int ord, in[N], out[N];
int v[N], opt[N], p[N], u[N], deg[N];
vector<int> E[N];
void dfs(int x) {
  in[x] = ++ord;
  for (int &i : E[x]) dfs(i);
  out[x] = ord;
}
inline int Pow(int a, int x) {
  int res = 1;
  while (x) {
    if (x & 1) res = (long long)res * a % Mod;
    a = (long long)a * a % Mod;
    x >>= 1;
  }
  return res;
}
long long sum[N << 2], w[N << 2];
long long lazy[N << 2];
int inv[N];
inline void pushdown(int &k) {
  if (!lazy[k]) return;
  if (lazy[k << 1])
    lazy[k << 1] = lazy[k << 1] * lazy[k] % Mod;
  else
    lazy[k << 1] = lazy[k];
  if (lazy[k << 1 | 1])
    lazy[k << 1 | 1] = lazy[k << 1 | 1] * lazy[k] % Mod;
  else
    lazy[k << 1 | 1] = lazy[k];
  sum[k << 1] = sum[k << 1] * lazy[k] % Mod;
  sum[k << 1 | 1] = sum[k << 1 | 1] * lazy[k] % Mod;
  w[k << 1] = w[k << 1] * lazy[k] % Mod;
  w[k << 1 | 1] = w[k << 1 | 1] * lazy[k] % Mod;
  lazy[k] = 0;
}
void Ins(int k, int l, int r, int p, int v, int v1) {
  if (l != r) pushdown(k);
  if (l == r) {
    sum[k] = v;
    w[k] = v1;
    return;
  }
  int mid = l + r >> 1;
  if (p <= mid)
    Ins(k << 1, l, mid, p, v, v1);
  else
    Ins(k << 1 | 1, mid + 1, r, p, v, v1);
  sum[k] = (sum[k << 1] + sum[k << 1 | 1]) % Mod;
}
void modify(int k, int l, int r, int p, int q, int v) {
  if (l != r) pushdown(k);
  if (l > q || r < p) return;
  if (l >= p && r <= q) {
    lazy[k] = v;
    sum[k] = sum[k] * v % Mod;
    w[k] = w[k] * v % Mod;
    return;
  }
  int mid = l + r >> 1;
  modify(k << 1, l, mid, p, q, v);
  modify(k << 1 | 1, mid + 1, r, p, q, v);
  sum[k] = (sum[k << 1] + sum[k << 1 | 1]) % Mod;
}
int Queryw(int k, int l, int r, int p) {
  if (l != r) pushdown(k);
  if (l == r) return w[k];
  int mid = l + r >> 1;
  if (p <= mid) return Queryw(k << 1, l, mid, p);
  return Queryw(k << 1 | 1, mid + 1, r, p);
}
int Querys(int k, int l, int r, int p, int q) {
  if (l != r) pushdown(k);
  if (l > q || r < p) return 0;
  if (l >= p && r <= q) return sum[k];
  int mid = l + r >> 1;
  return (Querys(k << 1, l, mid, p, q) + Querys(k << 1 | 1, mid + 1, r, p, q)) %
         Mod;
}
int main() {
  inv[0] = inv[1] = 1;
  for (int i = 2; i < N; i++)
    inv[i] = (long long)(Mod - Mod / i) * inv[Mod % i] % Mod;
  scanf("%d%d", v + 1, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", opt + i);
    if (opt[i] == 1) {
      n++;
      u[i] = n;
      scanf("%d%d", p + n, v + n);
      E[p[n]].push_back(n);
    } else {
      scanf("%d", u + i);
    }
  }
  dfs(1);
  Ins(1, 1, n, 1, v[1], 1);
  deg[1] = 1;
  for (int i = 1; i <= q; i++) {
    if (opt[i] == 1) {
      modify(1, 1, n, in[p[u[i]]], out[p[u[i]]],
             (long long)inv[deg[p[u[i]]]] * (deg[p[u[i]]] + 1) % Mod);
      deg[p[u[i]]]++;
      deg[u[i]] = 1;
      int W = Queryw(1, 1, n, in[p[u[i]]]);
      Ins(1, 1, n, in[u[i]], (long long)W * v[u[i]] % Mod, W);
    } else {
      int W = u[i] == 1 ? 1 : Queryw(1, 1, n, in[p[u[i]]]);
      int ans = (long long)Pow(W, Mod - 2) *
                Querys(1, 1, n, in[u[i]], out[u[i]]) % Mod;
      printf("%d\n", ans);
    }
  }
}
