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;
int n = 1, q, cnt, ver, Q[200010][4], in[200010], out[200010], v[200010],
    deg[200010], sum[200010 << 2], mul[200010 << 2], k[200010 << 2];
vector<int> G[200010];
inline void push_up(int o) {
  sum[o] = sum[o << 1] + sum[o << 1 | 1];
  if (sum[o] >= 1000000007) sum[o] -= 1000000007;
}
inline void push_down(int o) {
  if (mul[o] != 1) {
    sum[o << 1] = 1LL * sum[o << 1] * mul[o] % 1000000007;
    sum[o << 1 | 1] = 1LL * sum[o << 1 | 1] * mul[o] % 1000000007;
    k[o << 1] = 1LL * k[o << 1] * mul[o] % 1000000007;
    k[o << 1 | 1] = 1LL * k[o << 1 | 1] * mul[o] % 1000000007;
    mul[o << 1] = 1LL * mul[o << 1] * mul[o] % 1000000007;
    mul[o << 1 | 1] = 1LL * mul[o << 1 | 1] * mul[o] % 1000000007;
    mul[o] = 1;
  }
}
void build(int l, int r, int o) {
  mul[o] = 1;
  if (l == r) {
    if (l == 1)
      sum[o] = ver, k[o] = 1;
    else
      sum[o] = 0, k[o] = 0;
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, o << 1);
  build(mid + 1, r, o << 1 | 1);
  push_up(o);
}
void update(int L, int R, int val, int l, int r, int o) {
  if (R < l || r < L || R < L) return;
  if (L <= l && r <= R) {
    sum[o] = 1LL * sum[o] * val % 1000000007;
    k[o] = 1LL * k[o] * val % 1000000007;
    mul[o] = 1LL * mul[o] * val % 1000000007;
    return;
  }
  push_down(o);
  int mid = l + r >> 1;
  update(L, R, val, l, mid, o << 1);
  update(L, R, val, mid + 1, r, o << 1 | 1);
  push_up(o);
}
void change(int p, int val, int l, int r, int o) {
  if (l == r) {
    sum[o] = 1LL * val * v[p] % 1000000007;
    k[o] = val;
    mul[o] = 1;
    return;
  }
  push_down(o);
  int mid = l + r >> 1;
  if (p <= mid)
    change(p, val, l, mid, o << 1);
  else
    change(p, val, mid + 1, r, o << 1 | 1);
  push_up(o);
}
int query(int L, int R, int l, int r, int o) {
  if (R < l || r < L || R < L) return 0;
  if (L <= l && r <= R) return sum[o];
  push_down(o);
  int mid = l + r >> 1;
  return (query(L, R, l, mid, o << 1) + query(L, R, mid + 1, r, o << 1 | 1)) %
         1000000007;
}
int ask(int p, int l, int r, int o) {
  if (l == r) return k[o];
  push_down(o);
  int mid = l + r >> 1;
  if (p <= mid)
    return ask(p, l, mid, o << 1);
  else
    return ask(p, mid + 1, r, o << 1 | 1);
}
void dfs(int u) {
  in[u] = ++cnt;
  for (auto v : G[u]) dfs(v);
  out[u] = cnt;
}
int power(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % 1000000007;
    a = 1LL * a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d%d", &ver, &q);
  v[1] = ver;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &Q[i][0]);
    if (Q[i][0] == 1) {
      scanf("%d%d", &Q[i][1], &Q[i][3]);
      Q[i][2] = ++n;
      G[Q[i][1]].push_back(Q[i][2]);
    } else {
      scanf("%d", &Q[i][1]);
    }
  }
  dfs(1);
  for (int i = 1; i <= n; i++) deg[i] = 1;
  build(1, n, 1);
  for (int i = 1; i <= q; i++) {
    if (Q[i][0] == 1) {
      int fa = Q[i][1], u = Q[i][2];
      v[in[u]] = Q[i][3];
      update(in[fa], out[fa],
             1LL * (deg[fa] + 1) * power(deg[fa], 1000000007 - 2) % 1000000007,
             1, n, 1);
      deg[fa]++;
      change(in[u], ask(in[fa], 1, n, 1), 1, n, 1);
    } else {
      int u = Q[i][1], ans = query(in[u], out[u], 1, n, 1);
      ans = 1LL * ans * deg[u] % 1000000007;
      ans = 1LL * ans * power(ask(in[u], 1, n, 1), 1000000007 - 2) % 1000000007;
      printf("%d\n", ans);
    }
  }
  return 0;
}