#include <bits/stdc++.h>
using namespace std;
const long long MXN = 2e5 + 10;
const long long MXS = MXN * 4;
const long long Mod = 1e9 + 7;
long long power(long long a, long long b) {
  return (!b ? 1 : power(a * a % Mod, b / 2) * (b & 1LL ? a : 1) % Mod);
}
long long inv(long long x) { return power(x, Mod - 2); }
long long n, k, q, timer, ans;
long long Val[MXN], Typ[MXN], A[MXN], B[MXN], Stm[MXN], Ftm[MXN], deg[MXN];
long long seg[MXS], Sum[MXS], LzSum[MXS], Zrb[MXS], LzZrb[MXS];
vector<long long> adj[MXN];
void Build(long long id = 1, long long s = 1, long long e = n) {
  Zrb[id] = LzZrb[id] = 1;
  if ((e - s + 1) == 1) return;
  Build((id * 2), s, ((s + e) / 2)), Build((id * 2 + 1), ((s + e) / 2 + 1), e);
}
void Shift(long long id, long long s, long long e) {
  if (LzZrb[id] == 1 && LzSum[id] == 0) return;
  if ((e - s + 1) == 1) {
    Zrb[id] = Zrb[id] * LzZrb[id] % Mod;
    Sum[id] = (Sum[id] + LzSum[id]) % Mod;
    seg[id] = Sum[id] * Zrb[id] % Mod;
    LzZrb[id] = 1, LzSum[id] = 0;
    return;
  }
  seg[id] = seg[id] * LzZrb[id] % Mod;
  LzZrb[(id * 2)] = LzZrb[(id * 2)] * LzZrb[id] % Mod;
  LzZrb[(id * 2 + 1)] = LzZrb[(id * 2 + 1)] * LzZrb[id] % Mod;
  LzSum[(id * 2)] = (LzSum[(id * 2)] + LzSum[id]) % Mod;
  LzSum[(id * 2 + 1)] = (LzSum[(id * 2 + 1)] + LzSum[id]) % Mod;
  LzZrb[id] = 1, LzSum[id] = 0;
}
void Upd(long long l, long long r, long long sm, long long zrb,
         long long id = 1, long long s = 1, long long e = n) {
  Shift(id, s, e);
  if (e < l || s > r) return;
  if (l <= s && e <= r) {
    LzZrb[id] = zrb, LzSum[id] = sm;
    Shift(id, s, e);
    return;
  }
  Upd(l, r, sm, zrb, (id * 2), s, ((s + e) / 2)),
      Upd(l, r, sm, zrb, (id * 2 + 1), ((s + e) / 2 + 1), e);
  seg[id] = (seg[(id * 2)] + seg[(id * 2 + 1)]) % Mod;
}
long long Get(long long l, long long r, long long id = 1, long long s = 1,
              long long e = n) {
  Shift(id, s, e);
  if (e < l || s > r) return 0;
  if (l <= s && e <= r) return seg[id];
  long long now = (Get(l, r, (id * 2), s, ((s + e) / 2)) +
                   Get(l, r, (id * 2 + 1), ((s + e) / 2 + 1), e)) %
                  Mod;
  seg[id] = (seg[(id * 2)] + seg[(id * 2 + 1)]) % Mod;
  return now;
}
long long Gtz(long long ind, long long id = 1, long long s = 1,
              long long e = n) {
  Shift(id, s, e);
  if (e < ind || s > ind) return 1;
  if ((e - s + 1) == 1) return Zrb[id];
  long long now = Gtz(ind, (id * 2), s, ((s + e) / 2)) *
                  Gtz(ind, (id * 2 + 1), ((s + e) / 2 + 1), e);
  seg[id] = (seg[(id * 2)] + seg[(id * 2 + 1)]) % Mod;
  return now;
}
void dfs(long long u, long long par) {
  timer++, Stm[u] = timer;
  for (auto v : adj[u]) {
    if (v == par) continue;
    dfs(v, u);
  }
  Ftm[u] = timer;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> Val[1] >> q;
  n++;
  for (int i = 1; i <= q; i++) {
    cin >> Typ[i] >> A[i];
    if (Typ[i] == 1) {
      cin >> B[i];
      n++;
      Val[n] = B[i];
      adj[n].push_back(A[i]), adj[A[i]].push_back(n);
    }
  }
  dfs(1, 0);
  Build();
  k++;
  Upd(Stm[1], Stm[1], Val[1], 1);
  for (int i = 1; i <= q; i++) {
    if (Typ[i] == 1) {
      k++;
      Upd(Stm[k], Stm[k], Val[k], 1);
      Upd(Stm[A[i]], Ftm[A[i]], 0, inv(deg[A[i]] + 1));
      deg[A[i]]++;
      Upd(Stm[A[i]], Ftm[A[i]], 0, deg[A[i]] + 1);
      continue;
    }
    ans = Gtz(Stm[A[i]]);
    ans = inv(ans);
    ans = ans * Get(Stm[A[i]], Ftm[A[i]]) % Mod;
    cout << ans * (deg[A[i]] + 1) % Mod << '\n';
  }
  return 0;
}
