#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
int gcd(int x, int y) {
  while (y) {
    int t = x % y;
    x = y;
    y = t;
  }
  return x;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
namespace FastIO {
bool IOError = 0;
inline char NextChar() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOError = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool Blank(char c) {
  return c == ' ' || c == '\n' || c == '\r' || c == '\t';
}
inline void read(int &x) {
  bool sign = 0;
  char ch = NextChar();
  x = 0;
  for (; Blank(ch); ch = NextChar())
    ;
  if (IOError) return;
  if (ch == '-') sign = 1, ch = NextChar();
  for (; ch >= '0' && ch <= '9'; ch = NextChar()) x = x * 10 + ch - '0';
  if (sign) x = -x;
}
inline void read(long long &x) {
  bool sign = 0;
  char ch = NextChar();
  x = 0;
  for (; Blank(ch); ch = NextChar())
    ;
  if (IOError) return;
  if (ch == '-') sign = 1, ch = NextChar();
  for (; ch >= '0' && ch <= '9'; ch = NextChar()) x = x * 10 + ch - '0';
  if (sign) x = -x;
}
inline void read(double &x) {
  bool sign = 0;
  char ch = NextChar();
  x = 0;
  for (; Blank(ch); ch = NextChar())
    ;
  if (IOError) return;
  if (ch == '-') sign = 1, ch = NextChar();
  for (; ch >= '0' && ch <= '9'; ch = NextChar()) x = x * 10 + ch - '0';
  if (ch == '.') {
    double tmp = 1;
    ch = NextChar();
    for (; ch >= '0' && ch <= '9'; ch = NextChar())
      tmp /= 10.0, x += tmp * (ch - '0');
  }
  if (sign) x = -x;
}
inline void read(char *s) {
  char ch = NextChar();
  for (; Blank(ch); ch = NextChar())
    ;
  if (IOError) return;
  for (; !Blank(ch) && !IOError; ch = NextChar()) *s++ = ch;
  *s = 0;
}
inline void read(char &c) {
  for (c = NextChar(); Blank(c); c = NextChar())
    ;
  if (IOError) {
    c = -1;
    return;
  }
}
}  // namespace FastIO
using namespace FastIO;
vector<int> g[300100];
int inv[300100], deg[300100], n, q, a[300100], fa[300100], tot, st[300100],
    ed[300100];
int typ[300100], id[300100], sum[300100 << 2], tag[300100 << 2];
void dfs(int u) {
  st[u] = ++tot;
  for (auto v : g[u]) dfs(v);
  ed[u] = tot;
}
int mod_inv(int x) {
  return x <= n ? inv[x]
                : 1000000007 - (int)(1000000007 / x * 1LL *
                                     mod_inv(1000000007 % x) % 1000000007);
}
void up(int rt) {
  sum[rt] = sum[(rt << 1)] + sum[((rt << 1) | 1)];
  if (sum[rt] >= 1000000007) sum[rt] -= 1000000007;
}
void pd(int rt) {
  if (tag[rt] > 1) {
    sum[(rt << 1)] = 1LL * sum[(rt << 1)] * tag[rt] % 1000000007;
    tag[(rt << 1)] = 1LL * tag[(rt << 1)] * tag[rt] % 1000000007;
    sum[((rt << 1) | 1)] = 1LL * sum[((rt << 1) | 1)] * tag[rt] % 1000000007;
    tag[((rt << 1) | 1)] = 1LL * tag[((rt << 1) | 1)] * tag[rt] % 1000000007;
    tag[rt] = 1;
  }
}
void build(int rt, int ll, int rr) {
  sum[rt] = 0, tag[rt] = 1;
  if (ll == rr) return;
  build((rt << 1), ll, ((ll + rr) / 2));
  build(((rt << 1) | 1), ((ll + rr) / 2) + 1, rr);
}
void change(int rt, int ll, int rr, int x, int v) {
  if (ll == rr) {
    sum[rt] = v;
    return;
  }
  pd(rt);
  if (x <= ((ll + rr) / 2))
    change((rt << 1), ll, ((ll + rr) / 2), x, v);
  else
    change(((rt << 1) | 1), ((ll + rr) / 2) + 1, rr, x, v);
  up(rt);
}
void mul(int rt, int ll, int rr, int l, int r, int v) {
  if (l <= ll && r >= rr) {
    sum[rt] = 1LL * sum[rt] * v % 1000000007;
    tag[rt] = 1LL * tag[rt] * v % 1000000007;
    return;
  }
  pd(rt);
  if (l <= ((ll + rr) / 2)) mul((rt << 1), ll, ((ll + rr) / 2), l, r, v);
  if (r > ((ll + rr) / 2))
    mul(((rt << 1) | 1), ((ll + rr) / 2) + 1, rr, l, r, v);
  up(rt);
}
int query(int rt, int ll, int rr, int l, int r) {
  if (l <= ll && r >= rr) return sum[rt];
  pd(rt);
  int res = 0;
  if (l <= ((ll + rr) / 2)) {
    res += query((rt << 1), ll, ((ll + rr) / 2), l, r);
    if (res >= 1000000007) res -= 1000000007;
  }
  if (r > ((ll + rr) / 2)) {
    res += query(((rt << 1) | 1), ((ll + rr) / 2) + 1, rr, l, r);
    if (res >= 1000000007) res -= 1000000007;
  }
  up(rt);
  return res;
}
int main() {
  n = 0;
  read(a[++n]);
  read(q);
  for (int i = 0; i < q; i++) {
    read(typ[i]);
    if (typ[i] == 1) {
      id[i] = ++n;
      read(fa[n]);
      read(a[n]);
      g[fa[n]].push_back(n);
    } else {
      read(id[i]);
    }
  }
  inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = 1000000007 -
             (int)(1000000007 / i * 1LL * inv[1000000007 % i] % 1000000007);
  tot = 0;
  dfs(1);
  build(1, 1, n);
  deg[1] = 1;
  change(1, 1, n, 1, a[1]);
  for (int i = 0; i < q; i++) {
    if (typ[i] == 1) {
      int u = id[i], f = fa[u];
      mul(1, 1, n, st[f], st[u] - 1,
          1LL * inv[deg[f]] * (++deg[f]) % 1000000007);
      deg[u] = 1;
      change(1, 1, n, st[u],
             1LL * query(1, 1, n, st[f], st[f]) * mod_inv(a[f]) % 1000000007 *
                 a[u] % 1000000007);
    } else {
      int u = id[i];
      int ans = query(1, 1, n, st[u], ed[u]);
      if (fa[u])
        ans = 1LL * ans * mod_inv(query(1, 1, n, st[fa[u]], st[fa[u]])) %
              1000000007 * a[fa[u]] % 1000000007;
      printf("%d\n", ans);
    }
  }
  return 0;
}
