#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int v[200100];
struct IT {
  int d[800100];
  int s[800100];
  IT() {
    for (int i = 0; i <= 800000; i++) d[i] = 1;
  }
  void upd(int num, int l, int r, int x, int y, int z) {
    if (l > y || r < x || l > r) return;
    if (l >= x && y >= r) {
      if (z > 0) {
        d[num] = (1LL * d[num] * z) % mod;
        s[num] = (1LL * s[num] * z) % mod;
      } else
        s[num] -= (1LL * z * d[num]) % mod;
      return;
    }
    upd(num * 2, l, (l + r) / 2, x, y, z);
    upd(num * 2 + 1, (l + r) / 2 + 1, r, x, y, z);
    s[num] = (1LL * (s[num * 2] + s[num * 2 + 1]) * d[num]) % mod;
  }
  int get(int num, int l, int r, int x, int y) {
    if (l > y || r < x || l > r) return 0;
    if (l >= x && y >= r) {
      return s[num];
    }
    return (1LL *
            (get(num * 2, l, (l + r) / 2, x, y) +
             get(num * 2 + 1, (l + r) / 2 + 1, r, x, y)) *
            d[num]) %
           mod;
  }
} it, it2;
int s[200100];
int deg[200100];
int type[200100];
int x[200100];
int y[200100];
int inv[200100];
int z[200100];
int f[200100], cnt = 0;
vector<int> a[200100];
void dfs(int x, int last) {
  s[x] = ++cnt;
  for (int i = 0; i < a[x].size(); i++) {
    if (a[x][i] == last) continue;
    dfs(a[x][i], x);
  }
  f[x] = cnt;
}
int pow(int x, int y) {
  int s = 1;
  while (y) {
    if (y & 1) s = (1LL * s * x) % mod;
    x = (1LL * x * x) % mod;
    y >>= 1;
  }
  return s;
}
int main() {
  int q;
  scanf("%d %d", &v[1], &q);
  deg[1] = 1;
  cnt = 1;
  for (int i = 1; i <= 200000; i++) inv[i] = pow(i, mod - 2);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &type[i]);
    if (type[i] == 1) {
      scanf("%d %d", &x[i], &y[i]);
      z[i] = ++cnt;
      a[x[i]].push_back(z[i]);
    } else
      scanf("%d", &x[i]);
  }
  cnt = 0;
  dfs(1, 1);
  for (int i = 1; i <= cnt; i++) it2.upd(1, 1, cnt, i, i, -1);
  it.upd(1, 1, cnt, s[1], s[1], -v[1]);
  for (int i = 1; i <= q; i++) {
    if (type[i] == 1) {
      deg[x[i]]++;
      deg[z[i]] = 1;
      v[z[i]] = y[i];
      it.upd(1, 1, cnt, s[z[i]], s[z[i]], -y[i]);
      it.upd(1, 1, cnt, s[x[i]], f[x[i]], inv[deg[x[i]] - 1]);
      it2.upd(1, 1, cnt, s[x[i]], f[x[i]], inv[deg[x[i]]]);
      it2.upd(1, 1, cnt, s[x[i]], f[x[i]], deg[x[i]] - 1);
      it.upd(1, 1, cnt, s[x[i]], f[x[i]], deg[x[i]]);
    } else {
      cout << 1LL * it.get(1, 1, cnt, s[x[i]], f[x[i]]) *
                  it2.get(1, 1, cnt, s[x[i]], s[x[i]]) % mod * (deg[x[i]]) % mod
           << '\n';
    }
  }
}
