#include <bits/stdc++.h>
using namespace std;
template <typename T, typename L>
bool smax(T &x, L y) {
  return x < y ? (x = y, true) : false;
}
template <typename T, typename L>
bool smin(T &x, L y) {
  return y < x ? (x = y, true) : false;
}
struct Query {
  int t, p, v, u;
};
struct node {
  long long sm, lz;
  node() { sm = 0, lz = 1; }
};
void dfs(int);
void update(int, int, int, int, int);
void update(int, int, int, int, int, int);
int get(int, int, int, int);
void shift(int);
int query(int, int, int, int, int);
int mul(int, int);
int inv(int, int);
int pw(int, int);
int add(int, int);
const int MAXN = 2e5 + 15;
vector<int> val;
Query a[MAXN];
node tree[MAXN << 2];
int st[MAXN], ft[MAXN], ver[MAXN];
vector<int> adj[MAXN];
int d[MAXN], par[MAXN];
int n = 2, q, tme = 2;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cerr << "HELLO WORLD :)\n";
  val.resize(2);
  cin >> val[1] >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i].t;
    if (a[i].t == 1) {
      cin >> a[i].p >> a[i].v;
      val.push_back(a[i].v);
      par[n] = a[i].p;
      adj[a[i].p].push_back(n++);
    } else
      cin >> a[i].u;
  }
  dfs(1);
  update(1, 1, n, st[1], val[1]);
  for (int i = 0; i < q; i++) {
    if (a[i].t == 1) {
      int t = inv(d[a[i].p] + 2, d[a[i].p] + 1);
      update(1, 1, n, st[a[i].p], ft[a[i].p], t);
      int x = get(1, 1, n, st[a[i].p]);
      x = inv(x, val[a[i].p]);
      update(1, 1, n, st[tme++], mul(a[i].v, x));
      d[a[i].p]++;
    } else {
      int mem = query(1, 1, n, st[a[i].u], ft[a[i].u]);
      int rel = 1;
      if (a[i].u != 1) {
        rel = get(1, 1, n, st[par[a[i].u]]);
        rel = inv(rel, val[par[a[i].u]]);
      }
      mem = inv(mem, rel);
      cout << mem << '\n';
    }
  }
}
void dfs(int v) {
  static int t = 1;
  st[v] = t++;
  ver[st[v]] = v;
  for (auto u : adj[v]) dfs(u);
  ft[v] = t;
}
int pw(int p, int v) {
  int ret = 1;
  for (; v; v >>= 1, p = 1ll * p * p % 1000000007ll)
    if (v & 1) ret = 1ll * ret * p % 1000000007ll;
  return ret;
}
int mul(int a, int b) { return 1ll * a * b % 1000000007ll; }
int inv(int a, int b) { return mul(a, pw(b, 1000000007ll - 2)); }
int add(int a, int b) { return (a + b) % 1000000007ll; }
void shift(int id) {
  tree[id << 1].sm = mul(tree[id << 1].sm, tree[id].lz);
  tree[id << 1].lz = mul(tree[id << 1].lz, tree[id].lz);
  tree[id << 1 | 1].sm = mul(tree[id << 1 | 1].sm, tree[id].lz);
  tree[id << 1 | 1].lz = mul(tree[id << 1 | 1].lz, tree[id].lz);
  tree[id].lz = 1;
}
int query(int id, int b, int e, int l, int r) {
  if (b >= r || e <= l) return 0;
  if (b >= l && e <= r) return tree[id].sm;
  shift(id);
  int mid = (b + e) >> 1;
  return add(query(id << 1, b, mid, l, r), query(id << 1 | 1, mid, e, l, r));
}
int get(int id, int b, int e, int p) {
  if (b == e - 1) return tree[id].sm;
  shift(id);
  int mid = (b + e) >> 1;
  if (p < mid) return get(id << 1, b, mid, p);
  return get(id << 1 | 1, mid, e, p);
}
void update(int id, int b, int e, int l, int r, int val) {
  if (b >= r || e <= l) return;
  if (b >= l && e <= r) {
    tree[id].sm = mul(tree[id].sm, val);
    tree[id].lz = mul(tree[id].lz, val);
    return;
  }
  shift(id);
  int mid = (b + e) >> 1;
  update(id << 1, b, mid, l, r, val);
  update(id << 1 | 1, mid, e, l, r, val);
  tree[id].sm = add(tree[id << 1].sm, tree[id << 1 | 1].sm);
}
void update(int id, int b, int e, int p, int val) {
  if (b == e - 1) {
    tree[id].sm = val;
    return;
  }
  shift(id);
  int mid = (b + e) >> 1;
  if (p < mid)
    update(id << 1, b, mid, p, val);
  else
    update(id << 1 | 1, mid, e, p, val);
  tree[id].sm = add(tree[id << 1].sm, tree[id << 1 | 1].sm);
}
