Problem: Genos and Saitama went shopping for Christmas trees. However, a different type of tree caught their attention, the exalted Power Tree. 

A Power Tree starts out as a single root vertex indexed 1. A Power Tree grows through a magical phenomenon known as an update. In an update, a single vertex is added to the tree as a child of some other vertex.

Every vertex in the tree (the root and all the added vertices) has some value vi associated with it. The power of a vertex is defined as the strength of the multiset composed of the value associated with this vertex (vi) and the powers of its direct children. The strength of a multiset is defined as the sum of all elements in the multiset multiplied by the number of elements in it. Or in other words for some multiset S: 

<image>

Saitama knows the updates that will be performed on the tree, so he decided to test Genos by asking him queries about the tree during its growth cycle.

An update is of the form 1 p v, and adds a new vertex with value v as a child of vertex p.

A query is of the form 2 u, and asks for the power of vertex u.

Please help Genos respond to these queries modulo 109 + 7.

Input

The first line of the input contains two space separated integers v1 and q (1 ≤ v1 < 109, 1 ≤ q ≤ 200 000) — the value of vertex 1 and the total number of updates and queries respectively.

The next q lines contain the updates and queries. Each of them has one of the following forms: 

  * 1 pi vi, if these line describes an update. The index of the added vertex is equal to the smallest positive integer not yet used as an index in the tree. It is guaranteed that pi is some already existing vertex and 1 ≤ vi < 109. 
  * 2 ui, if these line describes a query. It is guaranteed ui will exist in the tree. 



It is guaranteed that the input will contain at least one query.

Output

For each query, print out the power of the given vertex modulo 109 + 7.

Examples

Input

2 5
1 1 3
1 2 5
1 3 7
1 4 11
2 1


Output

344


Input

5 5
1 1 4
1 2 3
2 2
1 2 7
2 1


Output

14
94

Note

For the first sample case, after all the updates the graph will have vertices labelled in the following manner: 1 — 2 — 3 — 4 — 5

These vertices will have corresponding values: 2 — 3 — 5 — 7 — 11

And corresponding powers: 344 — 170 — 82 — 36 — 11

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 19;
const int M = 1e9 + 7;
int tp[N], a[N], pv[N];
vector<int> con[N];
int sz[N], pa[N];
void dfs(int u) {
  sz[u] = 1;
  for (int v : con[u]) {
    dfs(v);
    sz[u] += sz[v];
  }
}
int hd[N], st[N], en[N], pid[N], T, pn = 1;
void hld(int u) {
  if (hd[pn] == 0) hd[pn] = u;
  int k(-1), mx(-1);
  st[u] = ++T;
  pid[u] = pn;
  for (int v : con[u])
    if (mx < sz[v]) mx = sz[v], k = v;
  if (k != -1) hld(k);
  for (int v : con[u]) {
    if (v == k) continue;
    pn += 2;
    hld(v);
  }
  en[u] = T;
}
int inv(int val) {
  int n = M - 2, ret = 1;
  for (; n; n >>= 1, val = 1LL * val * val % M)
    if (n % 2) ret = 1LL * ret * val % M;
  return ret;
}
int add[N], mul[N];
void down(int u) {
  if (mul[u] != 1) {
    mul[u + u] = 1LL * mul[u + u] * mul[u] % M;
    mul[u + u + 1] = 1LL * mul[u + u + 1] * mul[u] % M;
    add[u + u] = 1LL * add[u + u] * mul[u] % M;
    add[u + u + 1] = 1LL * add[u + u + 1] * mul[u] % M;
    mul[u] = 1;
  }
  if (add[u]) {
    add[u + u] = (add[u + u] + add[u]) % M;
    add[u + u + 1] = (add[u + u + 1] + add[u]) % M;
    add[u] = 0;
  }
}
void update(int u, int l, int r, int cl, int cr, int x, int y) {
  if (cl <= l && r <= cr) {
    add[u] = (add[u] + x) % M;
    mul[u] = 1LL * mul[u] * y % M;
    add[u] = 1LL * add[u] * y % M;
    return;
  }
  int md = l + r >> 1;
  down(u);
  if (cl <= md) update(u + u, l, md, cl, cr, x, y);
  if (md < cr) update(u + u + 1, md + 1, r, cl, cr, x, y);
}
int aa, bb;
void query(int u, int l, int r, int p) {
  if (l == p && r == p) {
    aa = add[u], bb = mul[u];
    return;
  }
  down(u);
  int md = l + r >> 1;
  if (p <= md)
    query(u + u, l, md, p);
  else
    query(u + u + 1, md + 1, r, p);
}
int main() {
  int n = 1, q;
  scanf("%d%d", a + 1, &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", tp + i, pv + i);
    if (tp[i] == 1) {
      int w;
      scanf("%d", &w);
      pa[++n] = pv[i];
      con[pv[i]].push_back(n);
      a[n] = w;
    }
  }
  dfs(1);
  hld(1);
  for (int i = 0; i < N; i++) add[i] = 0, mul[i] = 1, sz[i] = 1;
  update(1, 1, n, 1, 1, a[1], 1);
  int m = 1;
  for (int i = 0; i < q; i++) {
    int u = pv[i];
    query(1, 1, n, st[u]);
    if (tp[i] == 1) {
      ++m;
      int pp = 1LL * inv(sz[u]) * (sz[u] + 1) % M;
      update(1, 1, n, st[u] + 1, en[u], 0, pp);
      aa = 1LL * aa * inv(bb) % M;
      int dQ = (1LL * aa * inv(sz[u]) % M + a[m]) % M;
      dQ = (dQ + 1LL * a[m] * sz[u] % M) % M;
      sz[u]++;
      dQ = 1LL * dQ * bb % M;
      do {
        int tp = hd[pid[u]];
        int uu = st[tp];
        int vv = st[u];
        update(1, 1, n, uu, vv, dQ, 1);
        u = pa[tp];
      } while (u);
      update(1, 1, n, st[m], st[m], 1LL * sz[pv[i]] * bb % M * a[m] % M, 1);
    } else {
      int ans = 1LL * aa * inv(bb) % M;
      printf("%d\n", ans);
    }
  }
  return 0;
}