#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10, mod = 1e9 + 7;
int par[N], st[N], en[N], v[N], p[N], tim = 0, deg[N], t[N], val[N];
long long seg[4 * N], lazy[4 * N];
vector<int> adj[N];
int power(int a, int b) {
  if (b == 0) return 1;
  long long ret = power(a, b / 2);
  ret *= ret;
  ret %= mod;
  if (b % 2 == 1) ret *= a;
  ret %= mod;
  return ret;
}
void p_dfs(int x, int y = -1) {
  st[x] = tim++;
  par[x] = y;
  for (auto u : adj[x]) {
    if (u == y) continue;
    p_dfs(u, x);
  }
  en[x] = tim;
}
void shift(int id) {
  if (lazy[id] == 1) return;
  lazy[2 * id] *= lazy[id];
  lazy[2 * id] %= mod;
  seg[2 * id] *= lazy[id];
  seg[2 * id] %= mod;
  lazy[2 * id + 1] *= lazy[id];
  lazy[2 * id + 1] %= mod;
  seg[2 * id + 1] *= lazy[id];
  seg[2 * id + 1] %= mod;
  lazy[id] = 1;
  return;
}
void upd1(int id, int L, int R, int s, int e, int value) {
  if (L <= s && e <= R) {
    seg[id] *= value;
    seg[id] %= mod;
    lazy[id] *= value;
    lazy[id] %= mod;
    return;
  }
  if (L >= e || s >= R) return;
  int mid = (s + e) / 2;
  shift(id);
  upd1(2 * id, L, R, s, mid, value);
  upd1(2 * id + 1, L, R, mid, e, value);
  seg[id] = seg[2 * id] + seg[2 * id + 1];
  seg[id] %= mod;
  return;
}
void upd2(int id, int ind, int s, int e, int value) {
  if (e - s < 2) {
    seg[id] = value;
    return;
  }
  int mid = (s + e) / 2;
  shift(id);
  if (ind < mid)
    upd2(2 * id, ind, s, mid, value);
  else
    upd2(2 * id + 1, ind, mid, e, value);
  seg[id] = seg[2 * id] + seg[2 * id + 1];
  seg[id] %= mod;
  return;
}
int get(int id, int L, int R, int s, int e) {
  if (L <= s && e <= R) {
    return seg[id];
  }
  if (L >= e || s >= R) return 0;
  int mid = (s + e) / 2;
  shift(id);
  int ret = get(2 * id, L, R, s, mid);
  ret += get(2 * id + 1, L, R, mid, e);
  ret %= mod;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int v1, q, cnt = 2;
  cin >> v1 >> q;
  for (int i = 0; i < q; i++) {
    cin >> t[i];
    if (t[i] == 1)
      cin >> p[i] >> v[i];
    else
      cin >> v[i];
    if (t[i] == 1) {
      adj[p[i]].push_back(cnt);
      adj[cnt].push_back(p[i]);
      val[cnt] = v[i];
      cnt++;
    }
  }
  int n = cnt;
  adj[0].push_back(1);
  adj[1].push_back(0);
  p_dfs(0, -1);
  val[0] = 1;
  val[1] = v1;
  for (int i = 0; i < 4 * N; i++) lazy[i] = 1;
  upd2(1, st[1], 0, n, v1);
  upd2(1, st[0], 0, n, 1);
  cnt = 2;
  deg[0] = deg[1] = 1;
  for (int i = 0; i < q; i++) {
    if (t[i] == 2) {
      int u = v[i];
      long long ret = get(1, st[u], en[u], 0, n);
      long long ret2 = get(1, st[par[u]], st[par[u]] + 1, 0, n);
      ret2 *= power(val[par[u]], mod - 2);
      ret2 %= mod;
      ret *= power(ret2, mod - 2);
      ret %= mod;
      cout << ret << '\n';
    } else {
      long long value = deg[p[i]] + 1;
      upd1(1, st[p[i]], en[p[i]], 0, n, value);
      value = power(deg[p[i]], mod - 2);
      upd1(1, st[p[i]], en[p[i]], 0, n, value);
      long long ret = get(1, st[p[i]], st[p[i]] + 1, 0, n);
      ret *= power(val[p[i]], mod - 2);
      ret %= mod;
      ret *= v[i];
      ret %= mod;
      upd2(1, st[cnt], 0, n, ret);
      deg[cnt]++;
      deg[p[i]]++;
      cnt++;
    }
  }
}
