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, m, clk, Fa[200200], L[200200], R[200200], sum[200200 << 2],
    tag[200200 << 2], head[200200], cnt, du[200200], v1, opt[200200][3];
int Pow(int a, int k) {
  int ret = 1;
  while (k) {
    if (k & 1) ret = 1LL * ret * a % 1000000007;
    a = 1LL * a * a % 1000000007;
    k >>= 1;
  }
  return ret;
}
struct Edge {
  int to, next;
} edge[200200 << 1];
void AddEdge(int u, int v) {
  edge[++cnt] = (Edge){v, head[u]}, head[u] = cnt;
  edge[++cnt] = (Edge){u, head[v]}, head[v] = cnt;
}
void dfs(int u, int fa) {
  L[u] = ++clk;
  Fa[u] = fa;
  for (int i = head[u]; i; i = edge[i].next)
    if (edge[i].to != fa) dfs(edge[i].to, u);
  R[u] = clk;
}
void down(int rt) {
  int v = tag[rt];
  tag[rt] = 1;
  tag[rt << 1] = 1LL * tag[rt << 1] * v % 1000000007;
  sum[rt << 1] = 1LL * sum[rt << 1] * v % 1000000007;
  tag[rt << 1 | 1] = 1LL * tag[rt << 1 | 1] * v % 1000000007;
  sum[rt << 1 | 1] = 1LL * sum[rt << 1 | 1] * v % 1000000007;
}
void update(int rt, int l, int r, int p, int v) {
  if (l == r) {
    sum[rt] = 1LL * v * tag[rt] % 1000000007;
    return;
  }
  down(rt);
  if (p <= ((l + r) >> 1))
    update(rt << 1, l, ((l + r) >> 1), p, v);
  else
    update(rt << 1 | 1, ((l + r) >> 1) + 1, r, p, v);
  sum[rt] = (sum[rt << 1] + sum[rt << 1 | 1]) % 1000000007;
}
void update(int rt, int l, int r, int L, int R, int v) {
  if (l >= L && r <= R) {
    tag[rt] = 1LL * tag[rt] * v % 1000000007;
    sum[rt] = 1LL * sum[rt] * v % 1000000007;
    return;
  }
  down(rt);
  if (L <= ((l + r) >> 1)) update(rt << 1, l, ((l + r) >> 1), L, R, v);
  if (R > ((l + r) >> 1)) update(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R, v);
  sum[rt] = (sum[rt << 1] + sum[rt << 1 | 1]) % 1000000007;
}
int query_sum(int rt, int l, int r, int L, int R) {
  if (l >= L && r <= R) return sum[rt];
  down(rt);
  int ret = 0;
  if (L <= ((l + r) >> 1)) ret = query_sum(rt << 1, l, ((l + r) >> 1), L, R);
  if (R > ((l + r) >> 1))
    ret = (ret + query_sum(rt << 1 | 1, ((l + r) >> 1) + 1, r, L, R)) %
          1000000007;
  return ret;
}
int query_d(int rt, int l, int r, int p) {
  if (!p) return 1;
  if (l == r) return tag[rt];
  down(rt);
  if (p <= ((l + r) >> 1))
    return query_d(rt << 1, l, ((l + r) >> 1), p);
  else
    return query_d(rt << 1 | 1, ((l + r) >> 1) + 1, r, p);
}
int main() {
  scanf("%d%d", &v1, &m);
  n = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", opt[i] + 0, opt[i] + 1);
    if (opt[i][0] == 1)
      scanf("%d", opt[i] + 2), AddEdge(++n, opt[i][1]), opt[i][1] = n;
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) du[i] = 1;
  for (int i = 1; i <= n << 2; i++) tag[i] = 1;
  update(1, 1, n, L[1], v1);
  for (int i = 1; i <= m; i++) {
    if (opt[i][0] == 1) {
      int u = opt[i][1];
      update(1, 1, n, L[u], opt[i][2]);
      update(
          1, 1, n, L[Fa[u]], R[Fa[u]],
          1LL * (du[Fa[u]] + 1) * Pow(du[Fa[u]], 1000000007 - 2) % 1000000007);
      du[Fa[u]]++;
    } else {
      int u = opt[i][1];
      int d = query_d(1, 1, n, L[Fa[u]]);
      printf("%d\n", int(1LL * Pow(d, 1000000007 - 2) *
                         query_sum(1, 1, n, L[u], R[u]) % 1000000007));
    }
  }
}