#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int mod = 1e9 + 7;
int n, sz[N], son[N], top[N], id[N], ty[N], f[N], o[N], val[N], tot;
vector<int> g[N];
void dfs_1(int u, int fa) {
  sz[u]++;
  f[u] = fa;
  pair<int, int> mx = make_pair(0, 0);
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (v != fa) {
      dfs_1(v, u);
      sz[u] += sz[v];
      mx = max(mx, make_pair(sz[v], v));
    }
  }
  son[u] = mx.second;
}
void dfs_2(int u, int fa) {
  id[u] = ++tot;
  if (son[u]) {
    top[son[u]] = top[u];
    dfs_2(son[u], u);
  }
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (v != son[u] && v != fa) {
      top[v] = v;
      dfs_2(v, u);
    }
  }
}
struct node {
  int sum, mul;
  bool lazy;
} t[N << 2];
void push_down(int u) {
  if (t[u].lazy) {
    t[u << 1].sum =
        (t[u << 1].sum + 1LL * t[u].sum * t[u << 1 | 1].mul % mod) % mod;
    t[u << 1 | 1].sum = (t[u << 1 | 1].sum + t[u].sum) % mod;
    t[u << 1].lazy = t[u << 1 | 1].lazy = 1;
    t[u].sum = 0;
    t[u].lazy = 0;
  }
}
int update_sum(int u, int l, int r, int L, int R, int v) {
  if (l == L && r == R) {
    t[u].sum = (t[u].sum + v) % mod;
    t[u].lazy = 1;
    return t[u].mul;
  }
  push_down(u);
  int mid = (l + r) / 2;
  if (R <= mid)
    return update_sum(u << 1, l, mid, L, R, v);
  else if (L > mid)
    return update_sum(u << 1 | 1, mid + 1, r, L, R, v);
  else {
    int res = update_sum(u << 1 | 1, mid + 1, r, mid + 1, R, v);
    res = 1LL * res * update_sum(u << 1, l, mid, L, mid, 1LL * v * res % mod) %
          mod;
    return res;
  }
}
void update_mul(int u, int l, int r, int x) {
  if (l == r) {
    t[u].mul++;
    return;
  }
  push_down(u);
  int mid = (l + r) / 2;
  if (x <= mid)
    update_mul(u << 1, l, mid, x);
  else
    update_mul(u << 1 | 1, mid + 1, r, x);
  t[u].mul = 1LL * t[u << 1].mul * t[u << 1 | 1].mul % mod;
}
pair<int, int> query(int u, int l, int r, int x) {
  if (l == r) return make_pair(t[u].mul, t[u].sum);
  push_down(u);
  int mid = (l + r) / 2;
  if (x <= mid)
    return query(u << 1, l, mid, x);
  else
    return query(u << 1 | 1, mid + 1, r, x);
}
int main() {
  int V, q;
  scanf("%d%d", &V, &q);
  int cnt = 1;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &ty[i]);
    if (ty[i] == 1) {
      scanf("%d%d", &o[i], &val[i]);
      cnt++;
      g[o[i]].push_back(cnt);
      g[cnt].push_back(o[i]);
    } else
      scanf("%d", &o[i]);
  }
  top[1] = 1;
  dfs_1(1, 0);
  dfs_2(1, 0);
  update_sum(1, 1, tot, id[1], id[1], V);
  update_mul(1, 1, tot, id[1]);
  cnt = 1;
  for (int i = 1; i <= q; i++) {
    if (ty[i] == 1) {
      cnt++;
      update_sum(1, 1, tot, id[cnt], id[cnt], val[i]);
      update_mul(1, 1, tot, id[cnt]);
      pair<int, int> res = query(1, 1, tot, id[o[i]]);
      int ad = (res.second + 1LL * (res.first + 1) * val[i] % mod) % mod;
      update_sum(1, 1, tot, id[o[i]], id[o[i]], val[i]);
      update_mul(1, 1, tot, id[o[i]]);
      int x = f[o[i]];
      while (x) {
        int y = top[x];
        int res = update_sum(1, 1, tot, id[y], id[x], ad);
        ad = 1LL * res * ad % mod;
        x = f[y];
      }
    } else {
      pair<int, int> res = query(1, 1, tot, id[o[i]]);
      printf("%d\n", 1LL * res.first * res.second % mod);
    }
  }
  return 0;
}
