#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
int a, b, c, d, n, m, k;
int mas[200002], st[200002];
vector<int> gsm[200002];
const int MX = 5000;
int rev[MX + 1], val[MX + 1], sum[MX + 1], deg[MX + 1];
pair<int, int> pr[MX + 1];
pair<int, pair<int, int> > quer[200002];
int gpr[200002], cool[200002], gsum[200002], gdeg[200002];
void recalc(int v) {
  int cnt = 1, sum = mas[v];
  for (int _n(((int)((gsm[v]).size())) - 1), i(0); i <= _n; i++) {
    recalc(gsm[v][i]);
    ++cnt;
    sum += st[gsm[v][i]];
    if (sum >= 1000000007) sum -= 1000000007;
  }
  st[v] = (long long)sum * cnt % 1000000007;
  gsum[v] = sum;
  gdeg[v] = cnt;
}
void dfs(int v, int last, int p) {
  if (cool[v] != -1) {
    last = v;
    p = 1;
  } else {
    p = (long long)p * gdeg[v] % 1000000007;
  }
  for (int _n(((int)((gsm[v]).size())) - 1), i(0); i <= _n; i++) {
    int w = gsm[v][i];
    if (cool[w] != -1) {
      pr[cool[w]] = make_pair(cool[last], p);
    }
    dfs(w, last, p);
  }
}
void solve(pair<int, pair<int, int> > *quer, int m) {
  memset(cool, -1, sizeof(cool));
  int k = 0;
  cool[0] = k++;
  rev[0] = 0;
  for (int _n((m)-1), i(0); i <= _n; i++) {
    for (int _n((2) - 1), z(0); z <= _n; z++) {
      if (z == 1 && quer[i].first == 2) break;
      int w = z == 0 ? quer[i].second.first : quer[i].second.second;
      if (cool[w] != -1) continue;
      rev[k] = w;
      cool[w] = k++;
    }
  }
  if (k > MX) {
    throw std::runtime_error("WTF?!?!?");
  }
  for (int _n((k)-1), i(0); i <= _n; i++) {
    val[i] = st[rev[i]];
    sum[i] = gsum[rev[i]];
    deg[i] = gdeg[rev[i]];
    pr[i] = make_pair(-1, 0);
  }
  dfs(0, 0, 1);
  for (int _n((m)-1), i(0); i <= _n; i++) {
    if (quer[i].first == 1) {
      int par = cool[quer[i].second.first];
      int ch = cool[quer[i].second.second];
      int cv = mas[quer[i].second.second];
      pr[ch] = make_pair(par, 1);
      int delta = ((long long)deg[par] * cv + sum[par] + cv) % 1000000007;
      ++deg[par];
      sum[par] += cv;
      if (sum[par] >= 1000000007) sum[par] -= 1000000007;
      val[par] += delta;
      if (val[par] >= 1000000007) val[par] -= 1000000007;
      if (pr[par].first != -1) {
        sum[pr[par].first] =
            (sum[pr[par].first] + (long long)delta * pr[par].second) %
            1000000007;
      }
      val[ch] = cv;
      sum[ch] = cv;
      deg[ch] = 1;
      int v = par, p = delta;
      while (v != 0) {
        int ov = pr[v].first;
        p = (long long)p * pr[v].second % 1000000007;
        p = (long long)p * deg[ov] % 1000000007;
        val[ov] += p;
        if (val[ov] >= 1000000007) val[ov] -= 1000000007;
        if (pr[ov].first != -1) {
          sum[pr[ov].first] =
              (sum[pr[ov].first] + (long long)p * pr[ov].second) % 1000000007;
        }
        v = ov;
      }
    } else {
      printf("%d\n", val[cool[quer[i].second.first]]);
    }
  }
}
int main() {
  scanf("%d%d", &mas[0], &m);
  int k = 1;
  for (int _n((m)-1), i(0); i <= _n; i++) {
    scanf("%d", &a);
    if (a == 1) {
      scanf("%d%d", &a, &b);
      --a;
      quer[i] = make_pair(1, make_pair(a, k));
      gpr[k] = a;
      mas[k++] = b;
    } else {
      scanf("%d", &b);
      --b;
      quer[i] = make_pair(2, make_pair(b, -1));
    }
  }
  for (int _n((k)-1), i(0); i <= _n; i++) {
    gsm[i].clear();
  }
  int bl = sqrt((double)m) + 1;
  bl *= 2;
  for (int i = 0; i < m; i += bl) {
    recalc(0);
    solve(quer + i, min(bl, m - i));
    for (int j = i; j < i + bl && j < m; ++j) {
      if (quer[j].first == 1) {
        gsm[quer[j].second.first].push_back(quer[j].second.second);
      }
    }
  }
}
