#include <bits/stdc++.h>
using namespace std;
const int maxn = 2E5 + 20;
const long long mo = 1000000007;
struct Q {
  int opt;
  int qx, qy;
} q[maxn];
int n, m, i, j, In[maxn], Out[maxn], d_t, cur = 1, si[maxn], fa[maxn];
long long c[maxn * 20], va[maxn], Mark[maxn * 20 + 10];
vector<int> v[maxn];
void dfs(int k) {
  In[k] = ++d_t;
  for (int l = 0; l < v[k].size(); l++) {
    int to = v[k][l];
    dfs(to);
  }
  Out[k] = d_t;
}
void push_down(int o) {
  if (Mark[o] == 1) return;
  Mark[2 * o] = Mark[2 * o] * Mark[o] % mo;
  Mark[2 * o + 1] = Mark[2 * o + 1] * Mark[o] % mo;
  c[2 * o] = c[2 * o] * Mark[o] % mo;
  c[2 * o + 1] = c[2 * o + 1] * Mark[o] % mo;
  Mark[o] = 1;
}
long long f_c(int o, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return c[o];
  push_down(o);
  int mid = (l + r) >> 1;
  long long ret = 0;
  if (ql <= mid) ret = (ret + f_c(2 * o, l, mid, ql, qr)) % mo;
  if (qr > mid) ret = (ret + f_c(2 * o + 1, mid + 1, r, ql, qr)) % mo;
  return ret;
}
void Modify(int o, int l, int r, int ql, int qr, long long M) {
  if (ql <= l && r <= qr) {
    c[o] = c[o] * M % mo;
    Mark[o] = Mark[o] * M % mo;
    return;
  }
  push_down(o);
  int mid = (l + r) >> 1;
  if (ql <= mid) Modify(2 * o, l, mid, ql, qr, M);
  if (qr > mid) Modify(2 * o + 1, mid + 1, r, ql, qr, M);
  c[o] = (c[2 * o] + c[2 * o + 1]) % mo;
}
void Add(int o, int l, int r, int pos, long long A) {
  c[o] = (c[o] + A) % mo;
  if (l == r) return;
  push_down(o);
  int mid = (l + r) >> 1;
  if (pos <= mid)
    Add(2 * o, l, mid, pos, A);
  else
    Add(2 * o + 1, mid + 1, r, pos, A);
}
long long ksm(long long x, long long y) {
  long long ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = ret * x % mo;
    x = x * x % mo;
  }
  return ret % mo;
}
int main() {
  cin >> va[1] >> m;
  for (i = 1; i <= maxn * 20; i++) Mark[i] = 1;
  for (i = 1; i <= m; i++) {
    scanf("%d", &q[i].opt);
    if (q[i].opt == 1) {
      scanf("%d %d", &q[i].qx, &va[++cur]);
      q[i].qy = cur;
      v[q[i].qx].push_back(q[i].qy);
      fa[q[i].qy] = q[i].qx;
    } else
      scanf("%d", &q[i].qx);
  }
  n = cur;
  dfs(1);
  si[1] = 1;
  Add(1, 1, cur, In[1], va[1]);
  for (i = 1; i <= m; i++) {
    if (q[i].opt == 1) {
      si[q[i].qy] = 1;
      long long Si = f_c(1, 1, n, In[q[i].qx], In[q[i].qx]);
      Si = Si * ksm(va[q[i].qx], mo - 2) % mo;
      Add(1, 1, n, In[q[i].qy], va[q[i].qy] * Si % mo);
      long long Modi = ksm(si[q[i].qx], mo - 2) * (++si[q[i].qx]) % mo;
      Modify(1, 1, n, In[q[i].qx], Out[q[i].qx], Modi);
    } else {
      long long a = f_c(1, 1, n, In[q[i].qx], Out[q[i].qx]);
      long long b;
      if (q[i].qx == 1)
        b = 1;
      else {
        int FA = fa[q[i].qx];
        b = f_c(1, 1, n, In[FA], In[FA]);
        b = ksm(va[FA], mo - 2) % mo * b % mo;
        b = ksm(b, mo - 2);
      }
      printf("%I64d\n", a * b % mo);
    }
  }
  return 0;
}
