#include <bits/stdc++.h>
using namespace std;
const long long int md = 1e9 + 7;
const int MAXN = 2e5 + 5;
int q, n = 0, st[MAXN], ft[MAXN], tim = 0, par[MAXN], x[MAXN], ty[MAXN];
long long int w[MAXN], cnt[MAXN], k[MAXN * 4], cont[MAXN * 4], lazy[MAXN * 4];
vector<int> adj[MAXN];
void dfs(int v, int parv) {
  st[v] = tim;
  tim++;
  for (auto u : adj[v])
    if (u != parv) dfs(u, v);
  ft[v] = tim;
  return;
}
long long int inv(long long int a, long long int b = 1e9 + 5) {
  if (b == 0) return 1ll;
  long long int k = inv(a, b / 2);
  k *= k;
  k %= md;
  if (b % 2ll) k *= a;
  k %= md;
  return k;
}
void upd(int ind) {
  cont[ind * 2] *= lazy[ind];
  cont[ind * 2] %= md;
  cont[ind * 2 + 1] *= lazy[ind];
  cont[ind * 2 + 1] %= md;
  k[ind * 2] *= lazy[ind];
  k[ind * 2] %= md;
  k[ind * 2 + 1] *= lazy[ind];
  k[ind * 2 + 1] %= md;
  lazy[ind * 2] *= lazy[ind];
  lazy[ind * 2] %= md;
  lazy[ind * 2 + 1] *= lazy[ind];
  lazy[ind * 2 + 1] %= md;
  lazy[ind] = 1ll;
  return;
}
void up(int ind) {
  cont[ind] = (cont[ind * 2] + cont[ind * 2 + 1]) % md;
  return;
}
void turnon(long long int ww, int x, int b = 0, int e = n, int ind = 1) {
  if (b + 1 == e) {
    cont[ind] = ww;
    return;
  }
  upd(ind);
  int mid = (b + e) / 2;
  if (x < mid)
    turnon(ww, x, b, mid, ind * 2);
  else
    turnon(ww, x, mid, e, ind * 2 + 1);
  up(ind);
  return;
}
long long int getk(int x, int b = 0, int e = n, int ind = 1) {
  if (b + 1 == e) return k[ind];
  int mid = (b + e) / 2;
  long long int ret;
  upd(ind);
  if (x < mid)
    ret = getk(x, b, mid, ind * 2);
  else
    ret = getk(x, mid, e, ind * 2 + 1);
  up(ind);
  return ret;
}
void mul(long long int val, int l, int r, int b = 0, int e = n, int ind = 1) {
  if (r <= b || e <= l) return;
  if (l <= b && r >= e) {
    k[ind] *= val;
    k[ind] %= md;
    cont[ind] *= val;
    cont[ind] %= md;
    lazy[ind] *= val;
    lazy[ind] %= md;
    return;
  }
  upd(ind);
  int mid = (b + e) / 2;
  mul(val, l, r, b, mid, ind * 2);
  mul(val, l, r, mid, e, ind * 2 + 1);
  up(ind);
  return;
}
long long int getcont(int l, int r, int b = 0, int e = n, int ind = 1) {
  if (r <= b || e <= l) return 0ll;
  if (l <= b && r >= e) return cont[ind];
  upd(ind);
  int mid = (b + e) / 2;
  long long int ret = 0ll;
  ret = (ret + getcont(l, r, b, mid, ind * 2)) % md;
  ret = (ret + getcont(l, r, mid, e, ind * 2 + 1)) % md;
  up(ind);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < MAXN * 4; i++) lazy[i] = 1ll, k[i] = 1ll;
  for (int i = 0; i < MAXN; i++) cnt[i] = 1ll;
  cin >> w[0] >> q;
  n = 1;
  par[0] = -1;
  for (int i = 0; i < q; i++) {
    cin >> ty[i];
    if (ty[i] == 1) {
      x[i] = n;
      cin >> par[n] >> w[n];
      par[n]--;
      adj[par[n]].push_back(n);
      n++;
    } else {
      cin >> x[i];
      x[i]--;
    }
  }
  dfs(0, -1);
  turnon(w[0], st[0]);
  for (int i = 0; i < q; i++) {
    int v = x[i];
    if (ty[i] == 2) {
      long long int k2 = 1ll;
      if (v != 0) k2 = getk(st[par[v]]);
      k2 = inv(k2);
      k2 *= getcont(st[v], ft[v]);
      k2 %= md;
      cout << k2 << '\n';
    } else {
      long long int ww = getk(st[par[v]]);
      ww *= w[v];
      ww %= md;
      turnon(ww, st[v]);
      ww = (cnt[par[v]] + 1ll) * inv(cnt[par[v]]);
      ww %= md;
      cnt[par[v]]++;
      mul(ww, st[par[v]], ft[par[v]]);
    }
  }
  return 0;
}
