#include <bits/stdc++.h>
using namespace std;
int tym;
long long modulo(long long a, long long b, long long c) {
  long long x = 1LL, y = a;
  while (b > 0LL) {
    if (b % 2LL == 1LL) {
      x = (x * y) % c;
    }
    y = (y * y) % c;
    b /= 2LL;
  }
  return x % c;
}
struct node {
  int t, x;
  long long v;
} q[412345];
long long child[412345], val[412345];
int st[412345], en[412345], par[412345];
vector<int> adj[412345];
long long mul[6 * 412345], ans[6 * 412345], flag[6 * 412345];
void p_update(int n, int b, int e, int x, long long v) {
  if (flag[n] != 1) {
    mul[n] = ((mul[n] * flag[n]) % 1000000007LL);
    ans[n] = ((ans[n] * flag[n]) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * flag[n]) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * flag[n]) % 1000000007LL;
    }
    flag[n] = 1LL;
  }
  if (b > x || e < x) return;
  if (b == e && e == x) {
    ans[n] = (v * mul[n]) % 1000000007LL;
    return;
  }
  int l = n << 1, mid = (b + e) >> 1;
  p_update(l, b, mid, x, v);
  p_update(l + 1, mid + 1, e, x, v);
  mul[n] = (mul[l] + mul[l + 1]);
  ans[n] = (ans[l] + ans[l + 1]);
  if (ans[n] >= 1000000007LL) ans[n] -= 1000000007LL;
  if (mul[n] >= 1000000007LL) mul[n] -= 1000000007LL;
}
void r_update(int n, int b, int e, int x, int y, long long v) {
  if (flag[n] != 1) {
    mul[n] = ((mul[n] * flag[n]) % 1000000007LL);
    ans[n] = ((ans[n] * flag[n]) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * flag[n]) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * flag[n]) % 1000000007LL;
    }
    flag[n] = 1LL;
  }
  if (b > y || e < x) return;
  if (b >= x && e <= y) {
    mul[n] = ((mul[n] * v) % 1000000007LL);
    ans[n] = ((ans[n] * v) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * v) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * v) % 1000000007LL;
    }
    return;
  }
  int l = n << 1, mid = (b + e) >> 1;
  r_update(l, b, mid, x, y, v);
  r_update(l + 1, mid + 1, e, x, y, v);
  mul[n] = (mul[l] + mul[l + 1]);
  ans[n] = (ans[l] + ans[l + 1]);
  if (ans[n] >= 1000000007LL) ans[n] -= 1000000007LL;
  if (mul[n] >= 1000000007LL) mul[n] -= 1000000007LL;
}
long long r_query(int n, int b, int e, int x, int y) {
  if (flag[n] != 1) {
    mul[n] = ((mul[n] * flag[n]) % 1000000007LL);
    ans[n] = ((ans[n] * flag[n]) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * flag[n]) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * flag[n]) % 1000000007LL;
    }
    flag[n] = 1LL;
  }
  if (b > y || e < x) return 0LL;
  if (b >= x && e <= y) {
    return ans[n];
  }
  int l = n << 1, mid = (b + e) >> 1;
  long long an = r_query(l, b, mid, x, y) + r_query(l + 1, mid + 1, e, x, y);
  if (an >= 1000000007LL) an -= 1000000007LL;
  return an;
}
long long p_query(int n, int b, int e, int x) {
  if (flag[n] != 1) {
    mul[n] = ((mul[n] * flag[n]) % 1000000007LL);
    ans[n] = ((ans[n] * flag[n]) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * flag[n]) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * flag[n]) % 1000000007LL;
    }
    flag[n] = 1LL;
  }
  if (b > x || e < x) return 0LL;
  if (b == e && e == x) {
    return mul[n];
  }
  int l = n << 1, mid = (b + e) >> 1;
  long long an = p_query(l, b, mid, x) + p_query(l + 1, mid + 1, e, x);
  if (an >= 1000000007LL) an -= 1000000007LL;
  return an;
}
void build(int n, int b, int e) {
  flag[n] = 1LL;
  if (b == e) {
    mul[n] = 1LL;
    return;
  }
  int l = n << 1, mid = (b + e) >> 1;
  build(l, b, mid);
  build(l + 1, mid + 1, e);
  mul[n] = (mul[l] + mul[l + 1]);
  if (mul[n] >= 1000000007LL) mul[n] -= 1000000007LL;
}
void dfs(int u, int p) {
  st[u] = tym;
  par[u] = p;
  tym++;
  for (int i = 0; i < adj[u].size(); i++) dfs(adj[u][i], u);
  en[u] = tym - 1;
}
int main() {
  int i, j, n, qu;
  long long p;
  scanf("%lld %d", &p, &qu);
  val[1] = p;
  n = 2;
  for (i = 0; i < qu; i++) {
    scanf("%d", &q[i].t);
    if (q[i].t == 1) {
      int p;
      scanf("%d %lld", &p, &q[i].v);
      adj[p].push_back(n);
      q[i].x = n;
      val[n] = q[i].v;
      n++;
    } else
      scanf("%d", &q[i].x), q[i].v = 0LL;
  }
  tym = 0;
  n--;
  dfs(1, 0);
  build(1, 0, n - 1);
  child[1] = 1;
  p_update(1, 0, n - 1, st[1], val[1]);
  for (int i = 0; i < qu; i++) {
    if (q[i].t == 1) {
      int x = par[q[i].x];
      long long v =
          (modulo(child[x], 1000000007LL - 2, 1000000007LL) * (child[x] + 1)) %
          1000000007LL;
      r_update(1, 0, n - 1, st[x], en[x], v);
      child[x]++;
      child[q[i].x] = 1;
      p_update(1, 0, n - 1, st[q[i].x], q[i].v);
    } else {
      long long p, an = r_query(1, 0, n - 1, st[q[i].x], en[q[i].x]);
      if (q[i].x != 1)
        p = p_query(1, 0, n - 1, st[par[q[i].x]]);
      else
        p = 1;
      an = (an * modulo(p, 1000000007LL - 2, 1000000007LL)) % 1000000007LL;
      printf("%lld\n", an);
    }
  }
  return 0;
}
