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 mm = int(1e9) + 7;
struct sef {
  int ne, en;
} h[200050];
struct node {
  int k, x;
} Q[200050];
int tot, first[200050];
int pos[200050], To[200050], dfn[200050], sum, fa[200050];
int n, m;
long long son[200050], Val[200050];
long long S[1000050], V[1000050], M[1000050];
inline void setl(int x, int y) {
  h[++tot].ne = first[x];
  h[tot].en = y;
  first[x] = tot;
}
void Dfs(int x) {
  int y;
  dfn[++sum] = x;
  pos[x] = sum;
  for (int i = first[x]; y = h[i].en, i; i = h[i].ne) Dfs(y);
  To[x] = sum;
}
inline long long ksm(long long x, int y) {
  long long r = 1;
  while (y) {
    if (y & 1) r = r * x % mm;
    x = x * x % mm;
    y >>= 1;
  }
  return r;
}
void Build(int k, int l, int r) {
  S[k] = M[k] = 1;
  V[k] = 0;
  if (l == r) return;
  int mid = l + r >> 1;
  Build(k << 1, l, mid);
  Build(k << 1 | 1, mid + 1, r);
}
inline void Pd(int k) {
  if (M[k] != 1) {
    int l = k << 1;
    V[l] = V[l] * M[k] % mm;
    M[l] = M[l] * M[k] % mm;
    ++l;
    V[l] = V[l] * M[k] % mm;
    M[l] = M[l] * M[k] % mm;
    M[k] = 1;
  }
}
void Add_v(int k, int l, int r, const int &x, const long long &v) {
  if (l < r) Pd(k);
  if (l == r) {
    V[k] += v;
    if (V[k] >= mm) V[k] -= mm;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    Add_v(k << 1, l, mid, x, v);
  else
    Add_v(k << 1 | 1, mid + 1, r, x, v);
  V[k] = V[k << 1] + V[k << 1 | 1];
  if (V[k] >= mm) V[k] -= mm;
}
void Add_x(int k, int l, int r, const int &x, const int &y,
           const long long &v) {
  if (l < r) Pd(k);
  if (x <= l && r <= y) {
    V[k] = V[k] * v % mm;
    M[k] = M[k] * v % mm;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid) Add_x(k << 1, l, mid, x, y, v);
  if (y > mid) Add_x(k << 1 | 1, mid + 1, r, x, y, v);
  V[k] = V[k << 1] + V[k << 1 | 1];
  if (V[k] >= mm) V[k] -= mm;
}
void Add(int k, int l, int r, const int &x, const long long &v) {
  if (l == r) {
    S[k] = S[k] * v % mm;
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid)
    Add(k << 1, l, mid, x, v);
  else
    Add(k << 1 | 1, mid + 1, r, x, v);
  S[k] = S[k << 1] * S[k << 1 | 1] % mm;
}
long long Ask(int k, int l, int r, const int &x) {
  if (r <= x) return S[k];
  int mid = l + r >> 1;
  long long tmp = Ask(k << 1, l, mid, x);
  if (x > mid) tmp = tmp * Ask(k << 1 | 1, mid + 1, r, x) % mm;
  return tmp;
}
long long Query(int k, int l, int r, int x, int y) {
  if (l < r) Pd(k);
  if (x <= l && r <= y) return V[k];
  int mid = l + r >> 1;
  long long tmp = 0;
  if (x <= mid) tmp = Query(k << 1, l, mid, x, y);
  if (y > mid) tmp += Query(k << 1 | 1, mid + 1, r, x, y);
  if (tmp >= mm) tmp -= mm;
  return tmp;
}
int main() {
  scanf("%d%d", &Val[n = 1], &m);
  long long v;
  int x;
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &Q[i].k);
    if (Q[i].k == 1) {
      scanf("%d%I64d", &Q[i].x, &v);
      Val[++n] = v;
      setl(Q[i].x, n);
      fa[n] = Q[i].x;
    } else
      scanf("%d", &Q[i].x);
  }
  Dfs(1);
  son[n = 1] = 1;
  Build(1, 1, sum);
  Add(1, 1, sum, pos[1], 1);
  Add_v(1, 1, sum, pos[1], Val[1]);
  for (int i = 1; i <= m; ++i) {
    if (Q[i].k == 1) {
      ++n;
      son[n] = 1;
      x = Q[i].x;
      v = ksm(son[x], mm - 2);
      Add(1, 1, sum, pos[x], v);
      if (To[x] < sum) Add(1, 1, sum, To[x] + 1, son[x]);
      Add_x(1, 1, sum, pos[x], To[x], v);
      ++son[x];
      Add(1, 1, sum, pos[x], son[x]);
      if (To[x] < sum) Add(1, 1, sum, To[x] + 1, ksm(son[x], mm - 2));
      Add_x(1, 1, sum, pos[x], To[x], son[x]);
      v = Ask(1, 1, sum, pos[n]);
      Add_v(1, 1, sum, pos[n], v * Val[n] % mm);
    } else {
      x = Q[i].x;
      if (fa[x]) {
        v = Ask(1, 1, sum, pos[fa[x]]);
        v = ksm(v, mm - 2);
      } else
        v = 1;
      printf("%I64d\n", Query(1, 1, sum, pos[x], To[x]) * v % mm);
    }
  }
}