#include <bits/stdc++.h>
using namespace std;
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
const int N = 200001, NN = 262144, MOD = 1000000007;
int val[N], deg[N], par[N], pre[N], post[N], tick;
long long sum[2 * NN], mul[NN], tag[2 * NN];
pair<int, int> a[N];
vector<int> es[N];
void dfs(int u) {
  pre[u] = tick++;
  for (int v : es[u]) dfs(v);
  post[u] = tick;
}
void apply(int i, long long x) {
  sum[i] = sum[i] * x % MOD;
  if (NN <= i) mul[i - NN] = mul[i - NN] * x % MOD;
  tag[i] = tag[i] * x % MOD;
}
void mconcat(int i) { sum[i] = (sum[2 * i] + sum[2 * i + 1]) % MOD; }
void untag(int i) {
  if (i < 0 || NN <= i) return;
  i += NN;
  for (int j, h = 31 - __builtin_clz(NN); h; h--)
    if (tag[j = i >> h] != 1) {
      apply(2 * j, tag[j]);
      apply(2 * j + 1, tag[j]);
      tag[j] = 1;
    }
}
void multiply(int l, int r, long long x) {
  untag(l - 1);
  untag(r);
  bool lf = false, rf = false;
  long long s = 0;
  for (l += NN, r += NN; l < r;) {
    if (l & 1) lf = true, apply(l++, x);
    l >>= 1;
    if (lf) mconcat(l - 1);
    if (r & 1) rf = true, apply(--r, x);
    r >>= 1;
    if (rf) mconcat(r);
  }
  for (l--; l >>= 1, r >>= 1;) {
    if (lf || l == r) mconcat(l);
    if (rf && l != r) mconcat(r);
  }
}
void add(int i, long long x) {
  untag(i);
  i += NN;
  sum[i] = (sum[i] + x) % MOD;
  while (i >>= 1) mconcat(i);
}
long long getSum(int l, int r) {
  untag(l - 1);
  untag(r);
  long long s = 0;
  for (l += NN, r += NN; l < r; l >>= 1, r >>= 1) {
    if (l & 1) s = (s + sum[l++]) % MOD;
    if (r & 1) s = (s + sum[--r]) % MOD;
  }
  return s;
}
long long getMul(int i) {
  untag(i);
  return mul[i];
}
long long inv(long long x) {
  long long s = 1;
  for (; x > 1; x = MOD % x) s = s * (MOD - MOD / x) % MOD;
  return s;
}
int main() {
  val[0] = ri();
  int q = ri(), n = 1;
  for (int i = 0; i < (q); i++) {
    int op = ri(), x = ri() - 1;
    if (op == 1) {
      val[n] = ri();
      par[n] = x;
      es[x].push_back(n);
      a[i] = {op, n++};
    } else
      a[i] = {op, x};
  }
  dfs(0);
  fill_n(tag, 2 * NN, 1);
  add(pre[0], val[0]);
  mul[pre[0]] = 1;
  for (int i = 0; i < (q); i++) {
    int v = a[i].second;
    if (a[i].first == 1) {
      int u = par[v];
      deg[u]++;
      multiply(pre[u], post[u], (deg[u] + 1) * inv(deg[u]) % MOD);
      long long t = getMul(pre[u]);
      add(pre[v], val[v] * t % MOD);
      mul[pre[v]] = t;
    } else {
      long long t = getSum(pre[v], post[v]);
      if (v) t = t * (deg[v] + 1) % MOD * inv(getMul(pre[v])) % MOD;
      printf("%lld\n", t);
    }
  }
}
