#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
int const N = 2e5 + 20, mod = 1e9 + 7;
int q, n, tp[N], p[N], x[N], val[N], deg[N];
int tme, st[N], ft[N];
vector<int> g[N];
struct node {
  int sum, mul;
  node() : sum(0), mul(1) {}
} seg[N << 2];
inline void rel(int x) {
  if (x < 0) x += mod;
  if (x >= mod) x -= mod;
}
inline int pw(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) res = 1ll * res * a % mod;
  return res;
}
inline int inv(int x) { return pw(x, mod - 2); }
void pre_dfs(int v) {
  st[v] = tme++;
  for (int u : g[v]) pre_dfs(u);
  ft[v] = tme;
}
inline int get(int v) { return 1ll * seg[v].sum * seg[v].mul % mod; }
inline void pull(int v) {
  int lc = v << 1, rc = lc | 1;
  seg[v].sum = get(lc) + get(rc);
  rel(seg[v].sum);
}
void modify(int p, int val, int v = 1, int s = 0, int e = n) {
  if (e - s == 1) {
    seg[v].sum = val;
    return;
  }
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  if (p < mid)
    modify(p, val, lc, s, mid);
  else
    modify(p, val, rc, mid, e);
  pull(v);
}
void mul(int l, int r, int val, int v = 1, int s = 0, int e = n) {
  if (r <= s || e <= l) return;
  if (l <= s && e <= r) {
    seg[v].mul = 1ll * seg[v].mul * val % mod;
    return;
  }
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  mul(l, r, val, lc, s, mid);
  mul(l, r, val, rc, mid, e);
  pull(v);
}
int get_sum(int l, int r, int v = 1, int s = 0, int e = n) {
  if (r <= s || e <= l) return 0;
  if (l <= s && e <= r) return get(v);
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  int ret = get_sum(l, r, lc, s, mid) + get_sum(l, r, rc, mid, e);
  rel(ret);
  ret = 1ll * ret * seg[v].mul % mod;
  return ret;
}
int get_mul(int p, int v = 1, int s = 0, int e = n) {
  int ret = seg[v].mul;
  if (s + 1 == e) return ret;
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  if (p < mid)
    ret = 1ll * ret * get_mul(p, lc, s, mid) % mod;
  else
    ret = 1ll * ret * get_mul(p, rc, mid, e) % mod;
  return ret;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> val[0] >> q;
  n = 1;
  for (int i = 0; i < q; i++) {
    cin >> tp[i] >> p[i];
    p[i]--;
    if (tp[i] == 1) {
      x[i] = n++;
      cin >> val[x[i]];
      g[p[i]].push_back(x[i]);
    }
  }
  pre_dfs(0);
  deg[0] = 1;
  modify(st[0], val[0]);
  for (int i = 0; i < q; i++) {
    if (tp[i] == 1) {
      deg[x[i]] = 1;
      modify(st[x[i]], val[x[i]]);
      mul(st[p[i]], ft[p[i]], 1ll * inv(deg[p[i]]) * (++deg[p[i]]) % mod);
    } else {
      cout << 1ll * get_sum(st[p[i]], ft[p[i]]) * inv(get_mul(st[p[i]])) % mod *
                  deg[p[i]] % mod
           << '\n';
    }
  }
}
