#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void upmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void upmin(T &a, T b) {
  if (a > b) a = b;
}
const int maxn = 200007;
const int maxm = 200007;
const int maxs = maxn * 5;
const int mod = 1000000007;
const int inf = 0x7fffffff;
const double eps = 1e-7;
typedef int arr[maxn];
typedef int adj[maxm];
typedef int seg[maxs];
inline int fcmp(double a, double b) {
  if (fabs(a - b) <= eps) return 0;
  if (a < b - eps) return -1;
  return 1;
}
inline int add(int a, int b) { return ((long long)a + b) % mod; }
inline int mul(int a, int b) { return ((long long)a * b) % mod; }
inline int dec(int a, int b) { return add(a, mod - b % mod); }
inline int Pow(int a, int b) {
  int t = 1;
  while (b) {
    if (b & 1) t = mul(t, a);
    a = mul(a, a), b >>= 1;
  }
  return t;
}
template <typename Type>
inline Type RD() {
  char c = getchar();
  Type x = 0, flag = 1;
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    flag = -1;
  else
    x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  return x * flag;
}
inline char rdch() {
  char c = getchar();
  while (!isalpha(c)) c = getchar();
  return c;
}
namespace IO {
const int BUF = 20000000;
char Buf[BUF], *buf = Buf, *buff = Buf, _s[4];
void init() { fread(Buf, 1, BUF, stdin); }
void end() { fwrite(Buf, 1, buff - Buf, stdout); }
inline void read(int &a) {
  for (a = 0; *buf < 48; buf++)
    ;
  while (*buf > 47) a = a * 10 + *buf++ - 48;
}
inline void rdch(char &a) {
  for (a = 0; *buf < 'A'; buf++)
    ;
  a = *buf++;
}
inline void write(int a, char b) {
  if (!a)
    *buff++ = '0';
  else {
    char *s = _s;
    for (; a; a /= 10) *s++ = a % 10 + '0';
    while (s-- != _s) *buff++ = *s;
  }
  *buff++ = b;
}
}  // namespace IO
vector<int> G[maxn];
arr fa, deg;
inline void ins(int u, int v) { G[u].push_back(v), deg[u]++, fa[v] = u; }
arr a, inv;
int q, tot;
struct Que {
  int cmd, u, v;
};
Que que[maxn];
void input() {
  IO::read(a[1]), IO::read(q), tot = 1, deg[1] = 1;
  for (int i = 1, _ = q; i <= _; i++) {
    IO::read(que[i].cmd);
    if (que[i].cmd == 1) {
      deg[++tot] = 1;
      IO::read(que[i].u), IO::read(a[tot]);
      ins(que[i].u, tot), que[i].v = tot;
    } else
      IO::read(que[i].u);
  }
  inv[1] = 1;
  for (int i = 2, _ = q; i <= _; i++)
    inv[i] = dec(0, mul(mod / i, inv[mod % i]));
}
arr cnt, idx;
struct SegTree {
  seg val, tg;
  int ql, qr, v;
  void B(int flag, int u = 1, int l = 1, int r = tot) {
    tg[u] = 1;
    if (l == r) return (void)(val[u] = mul(flag ? a[idx[l]] : 1, cnt[idx[l]]));
    int m = (l + r) >> 1;
    B(flag, (u << 1), l, m), B(flag, (u << 1 | 1), m + 1, r);
    val[u] = add(val[(u << 1)], val[(u << 1 | 1)]);
  }
  inline void tag(int u, int v) {
    val[u] = mul(val[u], v);
    tg[u] = mul(tg[u], v);
  }
  inline void push(int u) {
    if (tg[u] == 1) return;
    tag((u << 1), tg[u]), tag((u << 1 | 1), tg[u]);
    tg[u] = 1;
  }
  void modi(int u = 1, int l = 1, int r = tot) {
    if (ql <= l && r <= qr) return (void)(tag(u, v));
    push(u);
    int m = (l + r) >> 1;
    if (ql <= m) modi((u << 1), l, m);
    if (qr > m) modi((u << 1 | 1), m + 1, r);
    val[u] = add(val[(u << 1)], val[(u << 1 | 1)]);
  }
  inline void M(int l, int r, int v) {
    if (l > r) return;
    ql = l, qr = r, this->v = v;
    modi();
  }
  int que(int u = 1, int l = 1, int r = tot) {
    if (ql <= l && r <= qr) return val[u];
    push(u);
    int m = (l + r) >> 1, t = 0;
    if (ql <= m) t = que((u << 1), l, m);
    if (qr > m) t = add(t, que((u << 1 | 1), m + 1, r));
    return t;
  }
  inline int Q(int l, int r) {
    if (!l) return 1;
    assert(l <= r);
    ql = l, qr = r;
    return que();
  }
} tr1, tr2;
arr st, ed;
void dfs(int u) {
  static int dfs_clock;
  st[u] = ++dfs_clock;
  idx[dfs_clock] = u;
  for (int v : G[u]) cnt[v] = mul(cnt[u], deg[v]), dfs(v);
  ed[u] = dfs_clock;
}
void solve() {
  cnt[1] = deg[1], dfs(1);
  tr1.B(1), tr2.B(0);
  static arr ans;
  for (int i = q, _ = 1; i >= _; i--)
    if (que[i].cmd == 1) {
      int u = que[i].v, p = que[i].u;
      int v = mul(deg[p] - 1, Pow(deg[p], mod - 2));
      tr1.M(st[p], ed[p], v);
      tr1.M(st[u], st[u], 0);
      tr2.M(st[p], ed[p], v);
      tr2.M(st[u], st[u], 0);
      deg[p]--;
    } else {
      int u = que[i].u;
      int v1 = tr1.Q(st[u], ed[u]), v2 = tr2.Q(st[fa[u]], st[fa[u]]);
      ans[i] = mul(v1, Pow(v2, mod - 2));
    }
  for (int i = 1, _ = q; i <= _; i++)
    if (que[i].cmd == 2) printf("%d\n", ans[i]);
}
int main() {
  IO::init();
  input();
  solve();
  return 0;
}
