#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, int b, int n) {
  long long int rm = 1;
  while (b) {
    if (b % 2) {
      rm = (rm * a) % n;
    }
    a = (a * a) % n;
    b /= 2;
  }
  return max(rm, 1ll);
}
const int N = 200009;
const int mod = 1000000007;
vector<int> edge[N];
long long int layer[4 * N + 1000], seg[4 * N + 1000] = {0};
int otype[N], p[N], t = 0, l[N], r[N], a[N], before[N] = {0}, rec[N], v[N],
                    u[N], v0[N] = {0};
void update0(int n, int it, int f, int q1, int q2, long long int val) {
  if (it == q1 && f == q2) {
    layer[n] = (layer[n] * val) % mod;
    if (it == f)
      seg[n] = 1ll * v0[a[f]] * layer[n];
    else
      seg[n] = (seg[n * 2] + seg[n * 2 + 1]) * layer[n];
    seg[n] %= mod;
    return;
  }
  int m = (it + f) / 2;
  if (q2 <= m)
    update0(n * 2, it, m, q1, q2, val);
  else if (q1 > m)
    update0(n * 2 + 1, m + 1, f, q1, q2, val);
  else {
    update0(n * 2, it, m, q1, m, val);
    update0(n * 2 + 1, m + 1, f, m + 1, q2, val);
  }
  seg[n] = (seg[n * 2] + seg[n * 2 + 1]) * layer[n];
  seg[n] %= mod;
}
void update1(int n, int it, int f, int q, long long int val) {
  if (it == f) {
    seg[n] = val * layer[n];
    seg[n] %= mod;
    return;
  }
  int m = (it + f) / 2;
  if (q <= m)
    update1(n * 2, it, m, q, val);
  else
    update1(n * 2 + 1, m + 1, f, q, val);
  seg[n] = (seg[n * 2] + seg[n * 2 + 1]) * layer[n];
  seg[n] %= mod;
}
long long int query(int n, int it, int f, int q1, int q2, long long int upper) {
  if (it == q1 && f == q2) {
    return (upper * seg[n]) % mod;
  }
  upper *= layer[n];
  upper %= mod;
  int m = (it + f) / 2;
  if (q2 <= m)
    return query(n * 2, it, m, q1, q2, upper);
  else if (q1 > m)
    return query(n * 2 + 1, m + 1, f, q1, q2, upper);
  else {
    long long int vvv1 = query(n * 2, it, m, q1, m, upper);
    vvv1 += query(n * 2 + 1, m + 1, f, m + 1, q2, upper);
    return vvv1 % mod;
  }
}
long long int query2(int n, int it, int f, int q, long long int prv) {
  prv *= layer[n];
  prv %= mod;
  if (it == f) return (prv * powmod(before[a[q]], mod - 2, mod)) % mod;
  int m = (it + f) / 2;
  if (q <= m)
    return query2(n * 2, it, m, q, prv);
  else
    return query2(n * 2 + 1, m + 1, f, q, prv);
}
void dfs(int vertex, int parent) {
  a[++t] = vertex;
  l[vertex] = t;
  for (int i = 0; i < edge[vertex].size(); ++i) {
    if (edge[vertex][i] != parent) {
      dfs(edge[vertex][i], vertex);
    }
  }
  r[vertex] = t;
}
int main() {
  int Q;
  int n = 1;
  long long int val, ans, ans2;
  cin >> v[1] >> Q;
  for (int i = int(1); i <= (int)Q; i++) {
    scanf("%d", &otype[i]);
    ;
    if (otype[i] == 1) {
      scanf("%d", &p[i]);
      ;
      scanf("%d", &val);
      ;
      ++n;
      edge[n].push_back(p[i]);
      edge[p[i]].push_back(n);
      rec[i] = n;
      v[n] = val;
    } else
      scanf("%d", &u[i]);
    ;
  }
  dfs(1, -1);
  for (int i = int(1); i <= (int)n; i++) before[i] = 1;
  fill(layer + 1, layer + 4 * N + 1, +1);
  update1(1, 1, n, l[1], v[1]);
  for (int i = int(1); i <= (int)Q; i++) {
    if (otype[i] == 1) {
      val = 1ll * (before[p[i]] + 1) * powmod(before[p[i]], mod - 2, mod);
      val %= mod;
      before[p[i]]++;
      if (val != 1) update0(1, 1, n, l[p[i]], r[p[i]], val);
      v0[rec[i]] = v[rec[i]];
      update1(1, 1, n, l[rec[i]], v[rec[i]]);
    } else {
      ans = query(1, 1, n, l[u[i]], r[u[i]], 1);
      ans2 = query2(1, 1, n, l[u[i]], 1);
      ans2 = powmod(ans2, mod - 2, mod);
      ans *= ans2;
      printf("%lld\n", ans % mod);
    }
  }
  return 0;
}
