#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T& x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T& x, L y) {
  return x > y ? (x = y, 1) : 0;
}
const int maxn = 2e5 + 17, mod = 1e9 + 7;
struct Seg {
  int lazy[maxn << 2], s[maxn << 2];
  void build(int l = 0, int r = maxn, int id = 1) {
    s[id] = r - l;
    if (r - l < 2) return;
    int mid = l + r >> 1;
    build(l, mid, id << 1), build(mid, r, id << 1 | 1);
  }
  Seg() { fill(lazy, lazy + (maxn << 2), 1), build(); }
  void shift(int id) {
    lazy[id << 1] = (long long)lazy[id << 1] * lazy[id] % mod,
               lazy[id << 1 | 1] =
                   (long long)lazy[id << 1 | 1] * lazy[id] % mod;
    s[id << 1] = (long long)s[id << 1] * lazy[id] % mod,
            s[id << 1 | 1] = (long long)s[id << 1 | 1] * lazy[id] % mod;
    lazy[id] = 1;
  }
  void add(int st, int en, int v, int l = 0, int r = maxn, int id = 1) {
    if (st <= l && r <= en) {
      s[id] = (long long)s[id] * v % mod,
      lazy[id] = (long long)lazy[id] * v % mod;
      return;
    }
    if (en <= l || r <= st) return;
    shift(id);
    int mid = l + r >> 1;
    add(st, en, v, l, mid, id << 1), add(st, en, v, mid, r, id << 1 | 1);
    s[id] = (s[id << 1] + s[id << 1 | 1]) % mod;
  }
  int get(int st, int en, int l = 0, int r = maxn, int id = 1) {
    if (st <= l && r <= en) return s[id];
    if (en <= l || r <= st) return 0;
    shift(id);
    int mid = l + r >> 1;
    return (get(st, en, l, mid, id << 1) + get(st, en, mid, r, id << 1 | 1)) %
           mod;
  }
  void add(int l, int v) { add(l, l + 1, v); }
  int get(int l) { return get(l, l + 1); }
} d, po, bad;
struct Q {
  int t, p, v;
} q[maxn];
int rev(int a) {
  int b = mod - 2, ans = 1;
  for (; b; b >>= 1) {
    if (b & 1) ans = (long long)ans * a % mod;
    a = (long long)a * a % mod;
  }
  return ans;
}
int tim, st[maxn], en[maxn], nq, deg[maxn], cnt = 1;
vector<int> g[maxn];
void dfs(int v = 0) {
  st[v] = tim++;
  for (auto u : g[v]) dfs(u);
  en[v] = tim;
}
void DeemoLovesInit() {
  int tmp;
  cin >> tmp >> nq;
  po.add(0, tmp);
  bad.add(0, 0);
  fill(deg, deg + maxn, 1);
  for (int i = 0; i < nq && cin >> q[i].t; i++)
    if (q[i].t == 1)
      cin >> q[i].p >> q[i].v, g[--q[i].p].push_back(cnt++);
    else
      cin >> q[i].v, q[i].v--;
  dfs();
  cnt = 1;
}
int main() {
  DeemoLovesInit();
  for (int i = 0, t = q[i].t, v = q[i].v, p = q[i].p; i < nq;
       i++, t = q[i].t, v = q[i].v, p = q[i].p)
    if (t == 1) {
      po.add(st[cnt],
             (long long)rev(po.get(st[cnt])) * v % mod * d.get(st[p]) % mod);
      bad.add(st[cnt], 0);
      deg[p]++;
      d.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod);
      po.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod);
      bad.add(st[p], en[p], (long long)rev(deg[p] - 1) * deg[p] % mod);
      cnt++;
    } else {
      cout << (long long)(po.get(st[v], en[v]) - bad.get(st[v], en[v]) + mod) %
                  mod * rev(d.get(st[v])) % mod * deg[v] % mod
           << '\n';
    }
  return 0;
}
