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;
long long mul_inv(long long a, long long b) {
  long long b0 = b, t, q;
  long long x0 = 0, x1 = 1;
  if (b == 1) {
    return 1;
  }
  while (a > 1) {
    q = a / b;
    t = b;
    b = a % b;
    a = t;
    t = x0;
    x0 = x1 - q * x0;
    x1 = t;
  }
  if (x1 < 0) {
    x1 += b0;
  }
  return x1;
}
const int MaxN = 300000;
int n, m;
vector<int> edge[MaxN];
int ss;
struct NODE {
  long long sum, lazy;
  long long ori;
} it[MaxN * 2];
int ord[MaxN];
int ordi;
pair<int, int> eu[MaxN];
long long a[MaxN];
int par[MaxN];
long long q[MaxN][3];
long long child[MaxN];
void back(int v, int parent) {
  ord[ordi++] = v;
  eu[v].first = ordi - 1;
  for (auto e : edge[v]) {
    if (e == parent) {
      continue;
    }
    back(e, v);
  }
  eu[v].second = ordi - 1;
}
void recalc(int v) {
  if (v >= ss) {
    it[v].sum = it[v].ori * it[v].lazy % 1000000007;
  } else {
    it[v].sum = (it[v * 2].sum + it[v * 2 + 1].sum) * it[v].lazy % 1000000007;
  }
}
void updateori(int x) {
  recalc(x);
  for (x /= 2; x > 0; x /= 2) {
    recalc(x);
  }
}
void update(int v, int vl, int vr, int l, int r, long long vv) {
  if (vl > vr) {
    return;
  }
  if (vl == l && vr == r) {
    it[v].lazy *= vv;
    it[v].lazy %= 1000000007;
    recalc(v);
    return;
  }
  it[v * 2].lazy *= it[v].lazy;
  it[v * 2 + 1].lazy *= it[v].lazy;
  it[v * 2].lazy %= 1000000007;
  it[v * 2 + 1].lazy %= 1000000007;
  it[v].lazy = 1;
  recalc(v * 2), recalc(v * 2 + 1);
  update(v * 2, vl, min(vr, (l + r) / 2), l, (l + r) / 2, vv);
  update(v * 2 + 1, max(vl, (l + r) / 2 + 1), vr, (l + r) / 2 + 1, r, vv);
  recalc(v);
}
long long getsum(int v, int vl, int vr, int l, int r) {
  if (vl > vr) {
    return 0;
  }
  if (vl == l && vr == r) {
    return it[v].sum;
  }
  it[v * 2].lazy *= it[v].lazy;
  it[v * 2 + 1].lazy *= it[v].lazy;
  it[v * 2].lazy %= 1000000007;
  it[v * 2 + 1].lazy %= 1000000007;
  it[v].lazy = 1;
  recalc(v * 2);
  recalc(v * 2 + 1);
  return (getsum(v * 2, vl, min(vr, (l + r) / 2), l, (l + r) / 2) +
          getsum(v * 2 + 1, max(vl, (l + r) / 2 + 1), vr, (l + r) / 2 + 1, r)) %
         1000000007;
}
int main() {
  cin >> a[0] >> m;
  n = 1;
  for (int i = 0; i < m; i++) {
    scanf("%I64d", &q[i][0]);
    if (q[i][0] == 1) {
      scanf("%I64d %I64d", &q[i][1], &q[i][2]);
      q[i][1]--;
      a[n++] = q[i][2];
      par[n - 1] = q[i][1];
      edge[n - 1].push_back(q[i][1]);
      edge[q[i][1]].push_back(n - 1);
    } else {
      scanf("%I64d", &q[i][1]);
      q[i][1]--;
    }
  }
  back(0, -1);
  ss = 1;
  while (ss < n) {
    ss *= 2;
  }
  int xn = 1;
  child[0] = 1;
  for (int i = 0; i < ss * 2; i++) {
    it[i].lazy = 1;
  }
  it[ss + eu[0].first].ori = a[0];
  updateori(ss + eu[0].first);
  for (int i = 0; i < m; i++) {
    if (q[i][0] == 1) {
      int x = q[i][1];
      update(1, eu[x].first, eu[x].second, 0, ss - 1,
             mul_inv(child[x], 1000000007));
      child[x]++;
      it[ss + eu[xn].first].ori = a[xn];
      updateori(ss + eu[xn].first);
      update(1, eu[x].first, eu[x].second, 0, ss - 1, child[x]);
      child[xn] = 1;
      xn++;
    } else {
      int x = q[i][1];
      long long res = getsum(1, eu[x].first, eu[x].second, 0, ss - 1);
      long long res2 = 1;
      if (x != 0) {
        res2 = getsum(1, eu[par[x]].first, eu[par[x]].first, 0, ss - 1);
        res2 *= mul_inv(a[par[x]], 1000000007);
        res2 %= 1000000007;
      }
      res *= mul_inv(res2, 1000000007);
      res %= 1000000007;
      printf("%I64d\n", res);
    }
  }
  return 0;
}