#include <bits/stdc++.h>
using namespace std;
const int N = 200005, Mod = 1e9 + 7;
int n, q, ts, A[N], D[N], P[N], Q[N], st[N], en[N];
int S[N * 4], Lz[N * 4];
vector<int> Adj[N];
inline int Power(int a, int b) {
  int ret = 1;
  for (; b; b >>= 1, a = 1ll * a * a % Mod)
    if (b & 1) ret = 1ll * ret * a % Mod;
  return (ret);
}
void DFS(int v) {
  st[v] = ts++;
  for (int &u : Adj[v]) DFS(u);
  en[v] = ts;
}
inline void Shift(int id) {
  if (Lz[id] == 1) return;
  Lz[(id + id)] = 1ll * Lz[(id + id)] * Lz[id] % Mod;
  Lz[(id + id + 1)] = 1ll * Lz[(id + id + 1)] * Lz[id] % Mod;
  S[(id + id)] = 1ll * S[(id + id)] * Lz[id] % Mod;
  S[(id + id + 1)] = 1ll * S[(id + id + 1)] * Lz[id] % Mod;
  Lz[id] = 1;
}
void Set(int i, int val, int id = 1, int l = 0, int r = ts) {
  if (r - l < 2) {
    S[id] = val;
    return;
  }
  Shift(id);
  if (i < ((l + r) >> 1))
    Set(i, val, (id + id), l, ((l + r) >> 1));
  else
    Set(i, val, (id + id + 1), ((l + r) >> 1), r);
  S[id] = (S[(id + id)] + S[(id + id + 1)]) % Mod;
}
void Mult(int le, int ri, int val, int id = 1, int l = 0, int r = ts) {
  if (ri <= l || r <= le) return;
  if (le <= l && r <= ri) {
    Lz[id] = 1ll * Lz[id] * val % Mod;
    S[id] = 1ll * S[id] * val % Mod;
    return;
  }
  Shift(id);
  Mult(le, ri, val, (id + id), l, ((l + r) >> 1));
  Mult(le, ri, val, (id + id + 1), ((l + r) >> 1), r);
  S[id] = (S[(id + id)] + S[(id + id + 1)]) % Mod;
}
int Get(int le, int ri, int id = 1, int l = 0, int r = ts) {
  if (ri <= l || r <= le) return (0);
  if (le <= l && r <= ri) return (S[id]);
  Shift(id);
  return ((Get(le, ri, (id + id), l, ((l + r) >> 1)) +
           Get(le, ri, (id + id + 1), ((l + r) >> 1), r)) %
          Mod);
}
int main() {
  scanf("%d%d", &A[++n], &q);
  for (int i = 1; i <= q; i++) {
    int t, p;
    scanf("%d%d", &t, &p);
    if (t == 1)
      scanf("%d", &A[++n]), P[n] = p, Q[i] = n, Adj[p].push_back(n);
    else
      Q[i] = -p;
  }
  DFS(1);
  memset(Lz, 1, sizeof(Lz));
  Set(st[1], A[1]);
  for (int i = 1; i <= q; i++) {
    int v = abs(Q[i]);
    if (Q[i] < 0) {
      if (v == 1)
        printf("%d\n", Get(st[v], en[v]));
      else
        printf("%lld\n", 1ll * Get(st[v], en[v]) *
                             Power(Get(st[P[v]], st[P[v]] + 1), Mod - 2) % Mod *
                             A[P[v]] % Mod);
    } else {
      int p = P[v], val = 1ll * Get(st[p], st[p] + 1) * Power(A[p], Mod - 2) %
                          Mod * A[v] % Mod;
      Set(st[v], val);
      D[p]++;
      Mult(st[p], en[p], (D[p] + 1) * 1ll * Power(D[p], Mod - 2) % Mod);
    }
  }
  return (0);
}
