#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline int add(int a, int b) {
  if ((a += b) >= mod) a -= mod;
  return a;
}
inline int mult(int a, int b) {
  long long t = 1ll * a * b;
  if (t >= mod) t %= mod;
  return t;
}
inline int power(int a, int b) {
  int out = 1;
  while (b) {
    if (b & 1) out = mult(out, a);
    a = mult(a, a);
    b >>= 1;
  }
  return out;
}
class segtree {
 public:
  int sum[800010], lzy[800010];
  void pushnow(int p, int v) {
    sum[p] = mult(sum[p], v);
    lzy[p] = mult(lzy[p], v);
  }
  void pushdown(int p) {
    if (lzy[p] != 1) {
      pushnow((p << 1), lzy[p]);
      pushnow(((p << 1) | 1), lzy[p]);
      lzy[p] = 1;
    }
  }
  void pushup(int p) { sum[p] = add(sum[(p << 1)], sum[((p << 1) | 1)]); }
  void build(int p, int l, int r) {
    lzy[p] = 1;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build((p << 1), l, mid);
    build(((p << 1) | 1), mid + 1, r);
  }
  void set(int p, int l, int r, int pos, int v) {
    if (l == r) {
      sum[p] = mult(lzy[p], v);
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (pos <= mid)
      set((p << 1), l, mid, pos, v);
    else
      set(((p << 1) | 1), mid + 1, r, pos, v);
    pushup(p);
  }
  void modify(int p, int l, int r, int ml, int mr, int v) {
    if (ml <= l && r <= mr) {
      pushnow(p, v);
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (ml <= mid) modify((p << 1), l, mid, ml, mr, v);
    if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, v);
    pushup(p);
  }
  int query(int p, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return sum[p];
    pushdown(p);
    int mid = (l + r) >> 1, ret = 0;
    if (ql <= mid) ret = query((p << 1), l, mid, ql, qr);
    if (qr > mid) ret = add(ret, query(((p << 1) | 1), mid + 1, r, ql, qr));
    return ret;
  }
  int qlzy(int p, int l, int r, int pos) {
    if (l == r) return lzy[p];
    pushdown(p);
    int mid = (l + r) >> 1;
    if (pos <= mid) return qlzy((p << 1), l, mid, pos);
    return qlzy(((p << 1) | 1), mid + 1, r, pos);
  }
} T;
vector<int> t[200010];
int n, q, v[200010], opt[200010], x[200010], y[200010], pos[200010],
    nodecnt = 1, dfn[200010], tim, R[200010], siz[200010];
void dfs(int np) {
  dfn[np] = ++tim;
  for (int x : t[np]) dfs(x);
  R[np] = tim;
}
int main() {
  scanf("%d%d", &v[1], &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &opt[i]);
    if (opt[i] == 1) {
      scanf("%d%d", &x[i], &y[i]);
      pos[i] = ++nodecnt;
      t[x[i]].push_back(pos[i]);
    } else {
      scanf("%d", &x[i]);
    }
  }
  n = nodecnt;
  dfs(1);
  T.build(1, 1, n);
  T.set(1, 1, n, dfn[1], v[1]);
  siz[1] = 1;
  for (int i = 1; i <= q; i++) {
    if (opt[i] == 1) {
      T.modify(1, 1, n, dfn[x[i]], R[x[i]],
               mult(siz[x[i]] + 1, power(siz[x[i]], mod - 2)));
      siz[x[i]]++;
      siz[pos[i]] = 1;
      T.set(1, 1, n, dfn[pos[i]], y[i]);
    } else {
      printf("%d\n",
             mult(siz[x[i]], mult(T.query(1, 1, n, dfn[x[i]], R[x[i]]),
                                  power(T.qlzy(1, 1, n, dfn[x[i]]), mod - 2))));
    }
  }
  return 0;
}
