#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
T sqr(const T &x) {
  return x * x;
}
template <class T>
T lowbit(const T &x) {
  return (x ^ (x - 1)) & x;
}
template <class T>
int countbit(const T &n) {
  return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
template <class T>
void ckmin(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
void ckmax(T &a, const T &b) {
  if (b > a) a = b;
}
const int maxn = (1 << 20);
const int MOD = 1000000007;
int n;
int m;
int a[maxn];
vector<int> g[maxn];
int v0[maxn], v1[maxn], v2[maxn], v3[maxn];
int sizeq;
int q[maxn], s[maxn], t[maxn];
int w[maxn];
int mul[maxn * 4];
int sum[maxn * 4];
void dfs(int p) {
  s[p] = sizeq;
  q[sizeq++] = p;
  for (int i = 0; i < (((int)(g[p].size()))); ++i) dfs(g[p][i]);
  t[p] = sizeq - 1;
}
void push(int id) {
  if (mul[id] == 1) return;
  int x = mul[id];
  mul[id] = 1;
  mul[id * 2 + 1] =
      ((int)((long long)(mul[id * 2 + 1]) * (long long)(x) % MOD));
  mul[id * 2 + 2] =
      ((int)((long long)(mul[id * 2 + 2]) * (long long)(x) % MOD));
  sum[id * 2 + 1] =
      ((int)((long long)(sum[id * 2 + 1]) * (long long)(x) % MOD));
  sum[id * 2 + 2] =
      ((int)((long long)(sum[id * 2 + 2]) * (long long)(x) % MOD));
}
void pop(int id) {
  sum[id] = ((int)((long long)(mul[id]) *
                   (long long)(sum[id * 2 + 1] + sum[id * 2 + 2]) % MOD));
}
void add_one(int id, int s, int t, int key) {
  if (s == t) {
    sum[id] = ((int)((long long)(mul[id]) * (long long)(a[s]) % MOD));
    return;
  }
  push(id);
  int m = (s + t) / 2;
  if (key <= m)
    add_one(id * 2 + 1, s, m, key);
  else
    add_one(id * 2 + 2, m + 1, t, key);
  pop(id);
}
int inverse(int x) {
  int e = MOD - 2;
  int r = 1;
  for (; e > 0; e /= 2) {
    if (e & 1) r = ((int)((long long)(r) * (long long)(x) % MOD));
    x = ((int)((long long)(x) * (long long)(x) % MOD));
  }
  return r;
}
void init(int id, int s, int t) {
  if (s == t) {
    mul[id] = 1;
    sum[id] = ((int)((long long)(mul[id]) * (long long)(a[q[s]]) % MOD));
    return;
  }
  mul[id] = 1;
  int m = (s + t) / 2;
  init(id * 2 + 1, s, m);
  init(id * 2 + 2, m + 1, t);
  pop(id);
}
void update(int id, int s, int t, int l, int r, int d) {
  if (s >= l && t <= r) {
    mul[id] = ((int)((long long)(mul[id]) * (long long)(d) % MOD));
    sum[id] = ((int)((long long)(sum[id]) * (long long)(d) % MOD));
    return;
  }
  push(id);
  int m = (s + t) / 2;
  if (l <= m) update(id * 2 + 1, s, m, l, r, d);
  if (m < r) update(id * 2 + 2, m + 1, t, l, r, d);
  pop(id);
}
int get_one(int id, int s, int t, int key) {
  if (s == t) return mul[id];
  push(id);
  int m = (s + t) / 2;
  return (key <= m) ? get_one(id * 2 + 1, s, m, key)
                    : get_one(id * 2 + 2, m + 1, t, key);
}
int get_sum(int id, int s, int t, int l, int r) {
  if (s >= l && t <= r) return sum[id];
  push(id);
  int m = (s + t) / 2;
  int ret = 0;
  if (l <= m) ret += get_sum(id * 2 + 1, s, m, l, r);
  if (m < r) ret += get_sum(id * 2 + 2, m + 1, t, l, r);
  if (ret >= MOD) ret -= MOD;
  return ret;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  n = 1;
  cin >> a[0] >> m;
  for (int i = 0; i < (m); ++i) {
    cin >> v0[i] >> v1[i];
    if (v0[i] == 1) cin >> v2[i];
  }
  for (int i = 0; i < (m); ++i)
    if (v0[i] == 1) {
      --v1[i];
      g[v1[i]].push_back(n);
      v3[i] = n;
      a[n] = v2[i];
      n++;
    } else {
      --v1[i];
    }
  sizeq = 0;
  dfs(0);
  for (int i = 0; i < (n); ++i) w[i] = ((int)(g[i].size())) + 1;
  init(0, 0, n - 1);
  for (int i = 0; i < (n); ++i) update(0, 0, n - 1, s[i], t[i], w[i]);
  for (int i = m - 1; i >= 0; i--)
    if (v0[i] == 1) {
      int key = v1[i];
      update(0, 0, n - 1, s[key], t[key],
             ((int)((long long)(inverse(w[key])) * (long long)((w[key] - 1)) %
                    MOD)));
      w[key]--;
      key = v3[i];
      update(0, 0, n - 1, s[key], t[key],
             ((int)((long long)(inverse(w[key])) * (long long)((w[key] - 1)) %
                    MOD)));
      w[key]--;
    } else {
      int key = v1[i];
      int val = get_one(0, 0, n - 1, s[key]);
      int ret = get_sum(0, 0, n - 1, s[key], t[key]);
      v2[i] = ((int)((long long)(inverse(val)) *
                     (long long)((
                         (int)((long long)(w[key]) * (long long)(ret) % MOD))) %
                     MOD));
    }
  for (int i = 0; i < (m); ++i)
    if (v0[i] == 2) printf("%d\n", v2[i]);
  return 0;
}
