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;
struct data {
  long long tag, sum, dg;
} t[200500 * 4];
struct edge {
  int obj, pre;
} e[200500 * 2];
int fa[200500], head[200500], st[200500], ed[200500], q[200500][2];
long long val[200500], deg[200500];
int n, m, tot, idx;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void insert(int x, int y) {
  e[++tot].obj = y;
  e[tot].pre = head[x];
  head[x] = tot;
}
long long Pow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % 1000000007;
    x = x * x % 1000000007;
    y /= 2;
  }
  return ans;
}
void dfs(int u) {
  st[u] = ++idx;
  for (int j = head[u]; j; j = e[j].pre) {
    int v = e[j].obj;
    dfs(v);
  }
  ed[u] = idx;
}
void get(int i, long long tag) {
  t[i].sum = (t[i].sum * tag) % 1000000007;
  t[i].dg = (t[i].dg * tag) % 1000000007;
  t[i].tag = (t[i].tag * tag) % 1000000007;
}
void Down(int i) {
  if (t[i].tag != 1) {
    long long tag = t[i].tag;
    get(i * 2, tag);
    get(i * 2 + 1, tag);
    t[i].tag = 1;
  }
}
void up(int i) {
  t[i].dg = (t[i * 2].dg + t[i * 2 + 1].dg) % 1000000007;
  t[i].sum = (t[i * 2].sum + t[i * 2 + 1].sum) % 1000000007;
}
void add(int i, int l, int r, int x, long long c, long long v) {
  if (l == r) {
    t[i].tag = 1;
    t[i].sum = (t[i].sum + c * v % 1000000007) % 1000000007;
    t[i].dg = (t[i].dg + c) % 1000000007;
    return;
  }
  Down(i);
  int mid = (l + r) / 2;
  if (x <= mid)
    add(i * 2, l, mid, x, c, v);
  else
    add(i * 2 + 1, mid + 1, r, x, c, v);
  up(i);
}
void mul(int i, int l, int r, int L, int R, long long c) {
  if (L <= l && r <= R) {
    get(i, c);
    return;
  }
  Down(i);
  int mid = (l + r) / 2;
  if (L <= mid) mul(i * 2, l, mid, L, R, c);
  if (R > mid) mul(i * 2 + 1, mid + 1, r, L, R, c);
  up(i);
}
long long ask(int i, int l, int r, int x) {
  if (l == r) return t[i].dg;
  Down(i);
  int mid = (l + r) / 2;
  if (x <= mid)
    return ask(i * 2, l, mid, x);
  else
    return ask(i * 2 + 1, mid + 1, r, x);
}
long long query(int i, int l, int r, int L, int R) {
  if (L <= l && r <= R) return t[i].sum;
  Down(i);
  int mid = (l + r) / 2;
  long long ans = 0;
  if (L <= mid) ans = (ans + query(i * 2, l, mid, L, R)) % 1000000007;
  if (R > mid) ans = (ans + query(i * 2 + 1, mid + 1, r, L, R) % 1000000007);
  return ans;
}
int main() {
  val[1] = read();
  m = read();
  n = 1;
  for (int i = 1; i <= m; i++) {
    q[i][0] = read();
    if (q[i][0] == 1) {
      q[i][1] = ++n;
      fa[n] = read();
      val[n] = read();
      insert(fa[n], n);
    } else
      q[i][1] = read();
  }
  dfs(1);
  for (int i = 1; i <= n; i++) deg[i] = 1;
  add(1, 1, n, 1, 1, val[1]);
  for (int i = 1; i <= m; i++) {
    if (q[i][0] == 1) {
      int v = q[i][1], u = fa[v];
      mul(1, 1, n, st[u], ed[u], 1 + Pow(deg[u], 1000000007 - 2));
      deg[u]++;
      long long pd = ask(1, 1, n, st[u]);
      add(1, 1, n, st[v], pd, val[v]);
    } else {
      int v = q[i][1], u = fa[v];
      long long ans = query(1, 1, n, st[v], ed[v]);
      if (u)
        ans = (ans * Pow(ask(1, 1, n, st[u]), 1000000007 - 2)) % 1000000007;
      printf("%lld\n", ans);
    }
  }
  return 0;
}