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 long long mod = 1000000007;
const int maxn = 200009;
long long pow(long long a, long long k) {
  long long ans = 1;
  while (k) {
    if (k & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    k /= 2;
  }
  return ans;
}
inline long long inv(long long a) { return pow(a, mod - 2); }
int n, q;
int val[maxn];
int curSize[maxn];
int maxSize[maxn];
int par[maxn];
int pos[maxn];
int t;
vector<int> neigh[maxn];
void DFS(int v) {
  maxSize[v] = 1;
  pos[v] = t++;
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    DFS(u);
    maxSize[v] += maxSize[u];
  }
}
pair<int, int> Q[maxn];
struct sTree {
  int L, R;
  int pl, pr;
  long long val;
  long long debtMult;
} tree[2 * maxn];
int treeSize;
void CalcDebt(int cur);
int BuildTree(int L, int R) {
  int cur = treeSize++;
  tree[cur].L = L;
  tree[cur].R = R;
  tree[cur].debtMult = 1;
  if (L < R) {
    tree[cur].pl = BuildTree(L, (L + R) / 2);
    tree[cur].pr = BuildTree((L + R) / 2 + 1, R);
  }
  return cur;
}
long long Get(int i, int cur) {
  if (tree[cur].L == tree[cur].R) return tree[cur].val;
  CalcDebt(cur);
  if (i <= tree[tree[cur].pl].R)
    return Get(i, tree[cur].pl);
  else
    return Get(i, tree[cur].pr);
}
long long Get(int L, int R, int cur) {
  if (L <= tree[cur].L && R >= tree[cur].R) return tree[cur].val;
  CalcDebt(cur);
  long long tmp = 0;
  if (L <= tree[tree[cur].pl].R && tree[tree[cur].pl].L <= R) {
    tmp = (tmp + Get(L, R, tree[cur].pl)) % mod;
  }
  if (L <= tree[tree[cur].pr].R && tree[tree[cur].pr].L <= R) {
    tmp = (tmp + Get(L, R, tree[cur].pr)) % mod;
  }
  return tmp;
}
void Add(int i, long long val, int cur) {
  if (tree[cur].L == tree[cur].R) {
    tree[cur].val =
        (tree[cur].val + val * (tree[cur].R - tree[cur].L + 1)) % mod;
    return;
  }
  CalcDebt(cur);
  if (i <= tree[tree[cur].pl].R) {
    Add(i, val, tree[cur].pl);
  } else {
    Add(i, val, tree[cur].pr);
  }
  tree[cur].val = tree[tree[cur].pl].val + tree[tree[cur].pr].val;
}
void Mult(int L, int R, long long val, int cur) {
  if (L <= tree[cur].L && R >= tree[cur].R) {
    tree[cur].debtMult = (tree[cur].debtMult * val) % mod;
    tree[cur].val = (tree[cur].val * val) % mod;
    return;
  }
  CalcDebt(cur);
  if (L <= tree[tree[cur].pl].R && tree[tree[cur].pl].L <= R) {
    Mult(L, R, val, tree[cur].pl);
  }
  if (L <= tree[tree[cur].pr].R && tree[tree[cur].pr].L <= R) {
    Mult(L, R, val, tree[cur].pr);
  }
  tree[cur].val = (tree[tree[cur].pl].val + tree[tree[cur].pr].val) % mod;
}
void CalcDebt(int cur) {
  if (tree[cur].L == tree[cur].R) return;
  if (tree[cur].debtMult != 1) {
    Mult(0, n - 1, tree[cur].debtMult, tree[cur].pl);
    Mult(0, n - 1, tree[cur].debtMult, tree[cur].pr);
    tree[cur].debtMult = 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  n = 1;
  cin >> val[1] >> q;
  for (int i = 0; i < q; i++) {
    cin >> Q[i].first;
    if (Q[i].first == 1) {
      n++;
      cin >> par[n] >> val[n];
      Q[i].second = n;
      neigh[par[n]].push_back(n);
    } else {
      cin >> Q[i].second;
    }
  }
  DFS(1);
  int root = BuildTree(0, n - 1);
  curSize[1] = 1;
  Add(pos[1], val[1], root);
  for (int i = 0; i < q; i++) {
    int v = Q[i].second;
    if (Q[i].first == 1) {
      int p = par[v];
      long long tmp = Get(pos[p], root);
      tmp = (tmp * inv(val[p])) % mod;
      tmp = (tmp * val[v]) % mod;
      Add(pos[v], tmp, root);
      Mult(pos[p], pos[p] + maxSize[p] - 1,
           ((curSize[p] + 1) * inv(curSize[p])) % mod, root);
      curSize[v]++;
      curSize[p]++;
    } else {
      long long tmp = Get(pos[v], pos[v] + maxSize[v] - 1, root);
      if (v != 1) {
        tmp = (tmp * inv((Get(pos[par[v]], root) * inv(val[par[v]])) % mod)) %
              mod;
      }
      cout << tmp << endl;
    }
  }
}