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>
#pragma warning(disable : 4996)
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;
}
int n, m;
vector<int> edge[300000];
int S;
struct NODE {
  long long sum, lazy;
  long long ori;
} it[600000];
int ord[300000];
int ordi;
pair<int, int> eu[300000];
long long a[300000];
int par[300000];
long long q[300000][3];
long long child[300000];
void back(int now, int parent) {
  ord[ordi++] = now;
  eu[now].first = ordi - 1;
  for (auto e : edge[now]) {
    if (e == parent) continue;
    back(e, now);
  }
  eu[now].second = ordi - 1;
}
void recalc(int now) {
  if (now >= S)
    it[now].sum = it[now].ori * it[now].lazy % 1000000007;
  else {
    it[now].sum =
        (it[now * 2].sum + it[now * 2 + 1].sum) * it[now].lazy % 1000000007;
  }
}
void updateori(int x) {
  recalc(x);
  for (x /= 2; x > 0; x /= 2) recalc(x);
}
void update(int now, int s, int e, int l, int r, long long v) {
  if (s > e) return;
  if (s == l && e == r) {
    it[now].lazy *= v;
    it[now].lazy %= 1000000007;
    recalc(now);
    return;
  }
  it[now * 2].lazy *= it[now].lazy, it[now * 2 + 1].lazy *= it[now].lazy,
      it[now * 2].lazy %= 1000000007, it[now * 2 + 1].lazy %= 1000000007,
      it[now].lazy = 1;
  recalc(now * 2), recalc(now * 2 + 1);
  update(now * 2, s, min(e, (l + r) / 2), l, (l + r) / 2, v);
  update(now * 2 + 1, max(s, (l + r) / 2 + 1), e, (l + r) / 2 + 1, r, v);
  recalc(now);
}
long long getsum(int now, int s, int e, int l, int r) {
  if (s > e) return 0;
  if (s == l && e == r) {
    return it[now].sum;
  }
  it[now * 2].lazy *= it[now].lazy, it[now * 2 + 1].lazy *= it[now].lazy,
      it[now * 2].lazy %= 1000000007, it[now * 2 + 1].lazy %= 1000000007,
      it[now].lazy = 1;
  recalc(now * 2), recalc(now * 2 + 1);
  return (getsum(now * 2, s, min(e, (l + r) / 2), l, (l + r) / 2) +
          getsum(now * 2 + 1, max(s, (l + r) / 2 + 1), e, (l + r) / 2 + 1, r)) %
         1000000007;
}
int main() {
  int i, j, k;
  cin >> a[0] >> m;
  n = 1;
  for (i = 0; i < m; i++) {
    scanf("%lld", &q[i][0]);
    if (q[i][0] == 1) {
      scanf("%lld%lld", &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("%lld", &q[i][1]);
      q[i][1]--;
    }
  }
  back(0, -1);
  for (S = 1; S < n; S *= 2)
    ;
  int xn = 1;
  child[0] = 1;
  for (i = 0; i < S * 2; i++) it[i].lazy = 1;
  it[S + eu[0].first].ori = a[0];
  updateori(S + eu[0].first);
  for (i = 0; i < m; i++) {
    if (q[i][0] == 1) {
      int x = q[i][1];
      update(1, eu[x].first, eu[x].second, 0, S - 1,
             mul_inv(child[x], 1000000007));
      child[x]++;
      it[S + eu[xn].first].ori = a[xn];
      updateori(S + eu[xn].first);
      update(1, eu[x].first, eu[x].second, 0, S - 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, S - 1);
      long long res2 = 1;
      if (x != 0) {
        res2 = getsum(1, eu[par[x]].first, eu[par[x]].first, 0, S - 1);
        res2 *= mul_inv(a[par[x]], 1000000007);
        res2 %= 1000000007;
      }
      res *= mul_inv(res2, 1000000007);
      res %= 1000000007;
      printf("%lld\n", res);
    }
  }
  return 0;
}