#include <bits/stdc++.h>
const long long mod = 1000000007;
using namespace std;
int len, nex[500000], hea[500000], wen[500000], l[500000], r[500000], q, n, cnt,
    fa[500000];
long long lazy[2000000], c[2000000], b[500000], v[500000], ans, inv;
struct arr {
  int bo, x;
} a[500000];
void add(int x, int y) {
  ++len;
  nex[len] = hea[x];
  wen[len] = y;
  hea[x] = len;
}
void dfs(int x) {
  l[x] = ++cnt;
  for (int i = hea[x]; i; i = nex[i]) dfs(wen[i]);
  r[x] = cnt;
}
void pushdown(int k) {
  if (lazy[k] == 1) return;
  long long t = lazy[k];
  c[k * 2] = c[k * 2] * t % mod;
  c[k * 2 + 1] = c[k * 2 + 1] * t % mod;
  lazy[k * 2] = lazy[k * 2] * t % mod;
  lazy[k * 2 + 1] = lazy[k * 2 + 1] * t % mod;
  lazy[k] = 1;
}
void update1(int l, int r, int k, int x, long long s) {
  if (l == r) {
    c[k] = s * lazy[k] % mod;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(k);
  if (x <= mid)
    update1(l, mid, k * 2, x, s);
  else
    update1(mid + 1, r, k * 2 + 1, x, s);
  c[k] = (c[k * 2] + c[k * 2 + 1]) % mod;
}
void update2(int l, int r, int k, int x, int y, long long z) {
  if (l >= x && y >= r) {
    lazy[k] = lazy[k] * z % mod;
    c[k] = c[k] * z % mod;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(k);
  if (x <= mid) update2(l, mid, k * 2, x, y, z);
  if (y > mid) update2(mid + 1, r, k * 2 + 1, x, y, z);
  c[k] = (c[k * 2] + c[k * 2 + 1]) % mod;
}
long long find(int l, int r, int k, int x, int y) {
  if (l >= x && y >= r) return (c[k] % mod);
  int mid = (l + r) >> 1;
  long long sum = 0;
  pushdown(k);
  if (x <= mid) sum += find(l, mid, k * 2, x, y);
  if (y > mid) sum += find(mid + 1, r, k * 2 + 1, x, y);
  return (sum % mod);
}
long long kp(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return (a % mod);
  long long c = kp(a, b / 2);
  c = (c * c) % mod;
  if (b & 1) c = (c * a) % mod;
  return c;
}
int main() {
  scanf("%lld%d", &v[1], &q);
  n = b[1] = 1;
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &a[i].bo, &a[i].x);
    if (2 - a[i].bo) {
      ++n;
      scanf("%lld", &v[n]);
      add(a[i].x, n);
      fa[n] = a[i].x;
    }
  }
  dfs(1);
  for (int i = 1; i <= n * 4; i++) lazy[i] = 1;
  update1(1, n, 1, 1, v[1]);
  int k = 1;
  for (int i = 1; i <= q; i++) {
    if (2 - a[i].bo) {
      ++k;
      ++b[a[i].x];
      ++b[k];
      update1(1, n, 1, l[k], v[k]);
      update2(1, n, 1, l[a[i].x], r[a[i].x],
              b[a[i].x] * kp(b[a[i].x] - 1, mod - 2) % mod);
    } else {
      int u = a[i].x;
      ans = find(1, n, 1, l[u], r[u]);
      if (u != 1)
        inv = v[fa[u]] * kp(find(1, n, 1, l[fa[u]], l[fa[u]]), mod - 2) % mod;
      else
        inv = 1;
      ans = ans * inv % mod;
      printf("%lld\n", ans);
    }
  }
}
