#include <bits/stdc++.h>
using namespace std;
int n, tip[1000005], val[1000005], p[1000005], l, coef[1000005], nrfii[1000005],
    nr[1000005];
int aint[4 * 1000005], sum[4 * 1000005], NOD, fat[1000005], nod[1000005];
vector<int> L[1000005];
inline void Dfs(int nod, int tata) {
  p[nod] = ++l;
  fat[nod] = tata;
  for (auto it : L[nod]) {
    if (it == tata) continue;
    Dfs(it, nod);
    nrfii[nod] += nrfii[it] + 1;
  }
}
inline void Propag(int nod) {
  if (aint[nod] == 1) return;
  aint[2 * nod] = (1LL * aint[2 * nod] * aint[nod]) % 1000000007;
  aint[2 * nod + 1] = (1LL * aint[2 * nod + 1] * aint[nod]) % 1000000007;
  sum[2 * nod] = (1LL * sum[2 * nod] * aint[nod]) % 1000000007;
  sum[2 * nod + 1] = (1LL * sum[2 * nod + 1] * aint[nod]) % 1000000007;
  aint[nod] = 1;
}
inline int Qry(int nod, int st, int dr, int x, int y) {
  if (st == x && y == dr) return sum[nod];
  Propag(nod);
  int mij = ((st + dr) >> 1);
  if (y <= mij)
    return Qry(2 * nod, st, mij, x, y);
  else if (x > mij)
    return Qry(2 * nod + 1, mij + 1, dr, x, y);
  else
    return (Qry(2 * nod, st, mij, x, mij) +
            Qry(2 * nod + 1, mij + 1, dr, mij + 1, y)) %
           1000000007;
}
inline int Pow_Log(int x, int p) {
  int sol = 1;
  while (p) {
    if (p & 1) {
      sol = (1LL * sol * x) % 1000000007;
      --p;
    }
    p >>= 1;
    x = (1LL * x * x) % 1000000007;
  }
  return sol;
}
inline void Upd(int nod, int st, int dr, int x, int y, int val) {
  if (st == x && y == dr) {
    aint[nod] = (1LL * aint[nod] * val) % 1000000007;
    sum[nod] = (1LL * sum[nod] * val) % 1000000007;
    NOD = nod;
    return;
  }
  Propag(nod);
  int mij = ((st + dr) >> 1);
  if (y <= mij)
    Upd(2 * nod, st, mij, x, y, val);
  else if (x > mij)
    Upd(2 * nod + 1, mij + 1, dr, x, y, val);
  else {
    Upd(2 * nod, st, mij, x, mij, val);
    Upd(2 * nod + 1, mij + 1, dr, mij + 1, y, val);
  }
  sum[nod] = (sum[2 * nod] + sum[2 * nod + 1]) % 1000000007;
}
inline int Coef(int nod) {
  if (!nod) return 1;
  Upd(1, 1, n, p[nod], p[nod], 1);
  return (1LL * coef[nod] * aint[NOD]) % 1000000007;
}
inline void Add(int nod, int st, int dr, int x, int val) {
  if (st == dr) {
    sum[nod] = val;
    return;
  }
  Propag(nod);
  int mij = ((st + dr) >> 1);
  if (x <= mij)
    Add(2 * nod, st, mij, x, val);
  else
    Add(2 * nod + 1, mij + 1, dr, x, val);
  sum[nod] = (sum[2 * nod] + sum[2 * nod + 1]) % 1000000007;
}
int main() {
  int i, j, cnt = 1, q;
  cin.sync_with_stdio(0);
  cin >> val[1] >> q;
  for (i = 1; i <= q; ++i) {
    cin >> tip[i];
    if (tip[i] == 2)
      cin >> nod[i];
    else {
      ++cnt;
      cin >> nod[i] >> val[cnt];
      L[cnt].push_back(nod[i]);
      L[nod[i]].push_back(cnt);
    }
  }
  n = cnt;
  for (i = 1; i <= 4 * n; ++i) aint[i] = 1;
  Dfs(1, 0);
  coef[1] = 1;
  Add(1, 1, n, 1, val[1]);
  for (i = cnt = 1; i <= q; ++i)
    if (tip[i] == 1) {
      ++cnt;
      int kkt =
          (1LL * (nr[nod[i]] + 2) * Pow_Log(nr[nod[i]] + 1, 1000000007 - 2)) %
          1000000007;
      Upd(1, 1, n, p[nod[i]], p[nod[i]] + nrfii[nod[i]], kkt);
      Upd(1, 1, n, p[cnt], p[cnt], 1);
      aint[NOD] = 1;
      coef[cnt] = Coef(nod[i]);
      Add(1, 1, n, p[cnt], (1LL * val[cnt] * coef[cnt]) % 1000000007);
      ++nr[nod[i]];
    } else {
      int val = Qry(1, 1, n, p[nod[i]], p[nod[i]] + nrfii[nod[i]]);
      val =
          (1LL * val * Pow_Log(Coef(fat[nod[i]]), 1000000007 - 2)) % 1000000007;
      cout << val << "\n";
    }
  return 0;
}
