#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 62;
const int mods = 1e9 + 7;
const int MAXN = 400005;
const int INF = 0x3f3f3f3f;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
pair<int, int> Q[MAXN];
vector<int> e[MAXN];
int n, DFN = 0, dfn[MAXN], fns[MAXN], sz[MAXN], fa[MAXN], c[MAXN];
int upd(int x, int y) { return x + y >= mods ? x + y - mods : x + y; }
int quick_pow(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = 1ll * ret * x % mods;
    x = 1ll * x * x % mods;
  }
  return ret;
}
int Inv(int x) { return quick_pow(x, mods - 2); }
void dfs(int x) {
  dfn[x] = ++DFN;
  for (auto v : e[x]) dfs(v);
  fns[x] = DFN;
}
int s[MAXN << 2], tag[MAXN << 2];
void build(int x, int l, int r) {
  tag[x] = 1, s[x] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
}
void down(int x) {
  if (tag[x] == 1) return;
  tag[x << 1] = 1ll * tag[x << 1] * tag[x] % mods;
  tag[x << 1 | 1] = 1ll * tag[x << 1 | 1] * tag[x] % mods;
  s[x << 1] = 1ll * s[x << 1] * tag[x] % mods;
  s[x << 1 | 1] = 1ll * s[x << 1 | 1] * tag[x] % mods;
  tag[x] = 1;
}
int query(int x, int l, int r, int L, int R) {
  if (l >= L && r <= R) return s[x];
  down(x);
  int mid = (l + r) >> 1;
  if (R <= mid)
    return query(x << 1, l, mid, L, R);
  else if (L > mid)
    return query(x << 1 | 1, mid + 1, r, L, R);
  else
    return upd(query(x << 1, l, mid, L, mid),
               query(x << 1 | 1, mid + 1, r, mid + 1, R));
}
void update(int x, int l, int r, int L, int R, int y) {
  if (l >= L && r <= R) {
    s[x] = 1ll * s[x] * y % mods, tag[x] = 1ll * tag[x] * y % mods;
    return;
  }
  down(x);
  int mid = (l + r) >> 1;
  if (R <= mid)
    update(x << 1, l, mid, L, R, y);
  else if (L > mid)
    update(x << 1 | 1, mid + 1, r, L, R, y);
  else
    update(x << 1, l, mid, L, mid, y),
        update(x << 1 | 1, mid + 1, r, mid + 1, R, y);
  s[x] = upd(s[x << 1], s[x << 1 | 1]);
}
void change(int x, int l, int r, int y, int z) {
  if (l == r) {
    s[x] = upd(s[x], z);
    return;
  }
  down(x);
  int mid = (l + r) >> 1;
  if (y <= mid)
    change(x << 1, l, mid, y, z);
  else
    change(x << 1 | 1, mid + 1, r, y, z);
  s[x] = upd(s[x << 1], s[x << 1 | 1]);
}
signed main() {
  c[1] = read(), n = 1;
  int m = read();
  for (int i = 1; i <= m; i++) {
    int opt = read();
    if (opt == 1)
      fa[++n] = read(), e[fa[n]].push_back(n), c[n] = read(),
      Q[i] = make_pair(1, n);
    else
      Q[i] = make_pair(2, read());
  }
  dfs(1);
  build(1, 1, n);
  change(1, 1, n, dfn[1], c[1]);
  for (int i = 1; i <= n; i++) sz[i] = 1;
  for (int i = 1; i <= m; i++) {
    int v = Q[i].second, Fa = fa[v];
    if (Q[i].first == 1) {
      int t = query(1, 1, n, dfn[Fa], dfn[Fa]);
      int p = 1ll * t * c[v] % mods * Inv(c[Fa]) % mods;
      change(1, 1, n, dfn[v], p);
      update(1, 1, n, dfn[Fa], fns[Fa],
             1ll * (sz[Fa] + 1) * Inv(sz[Fa]) % mods);
      sz[Fa]++;
    } else {
      int t = query(1, 1, n, dfn[v], fns[v]);
      if (v != 1)
        t = 1ll * t * Inv(query(1, 1, n, dfn[Fa], dfn[Fa])) % mods * c[Fa] %
            mods;
      printf("%d\n", t);
    }
  }
  return 0;
}
