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 N = 300010;
struct Query {
  int type, v;
  Query(){};
  Query(int type, int v) : type(type), v(v){};
};
struct Node {
  int val, d, upd;
  Node(){};
  Node(int val, int d, int upd) : val(val), d(d), upd(upd){};
};
const int MOD = 1e9 + 7;
int n, q, x, c[N], tcur, tin[N], tin1[N], parent[N], lt[N], rt[N], s[N];
Node tree[4 * N];
vector<int> g[N];
Query queries[N];
void dfs(int v) {
  tcur++;
  tin[v] = tcur;
  tin1[tin[v]] = v;
  lt[v] = tin[v];
  rt[v] = tin[v];
  for (int i = 0; i < g[v].size(); i++) {
    dfs(g[v][i]);
    rt[v] = max(rt[v], rt[g[v][i]]);
  }
}
void mult(int &a, int b) { a = (1ll * a * b) % MOD; }
int product(int a, int b) { return (1ll * a * b) % MOD; }
int sum(int a, int b) { return (a + b) % MOD; }
int power(int b, int p) {
  int res = 1;
  while (p) {
    if (p & 1) res = product(res, b);
    b = product(b, b);
    p /= 2;
  }
  return res;
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    tree[v] = Node(0, 1, 1);
    return;
  }
  int tm = (tl + tr) / 2;
  build(v * 2, tl, tm);
  build(v * 2 + 1, tm + 1, tr);
  tree[v] = Node(0, 1, 1);
}
void push(int v) {
  if (tree[v].upd != 1) {
    mult(tree[v * 2].val, tree[v].upd);
    mult(tree[v * 2 + 1].val, tree[v].upd);
    mult(tree[v * 2].d, tree[v].upd);
    mult(tree[v * 2 + 1].d, tree[v].upd);
    mult(tree[v * 2].upd, tree[v].upd);
    mult(tree[v * 2 + 1].upd, tree[v].upd);
    tree[v].upd = 1;
  }
}
void multOnSegment(int v, int tl, int tr, int l, int r, int val) {
  if (l > r) return;
  if (l == tl && r == tr) {
    mult(tree[v].val, val);
    mult(tree[v].d, val);
    mult(tree[v].upd, val);
    return;
  }
  push(v);
  int tm = (tl + tr) / 2;
  multOnSegment(v * 2, tl, tm, l, min(r, tm), val);
  multOnSegment(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
  tree[v].val = sum(tree[v * 2].val, tree[v * 2 + 1].val);
  tree[v].d = sum(tree[v * 2].d, tree[v * 2 + 1].d);
}
void update(int v, int tl, int tr, int pos) {
  if (tl == tr) {
    tree[v].val = product(c[tin1[tl]], tree[v].d);
    return;
  }
  push(v);
  int tm = (tl + tr) / 2;
  if (pos <= tm)
    update(v * 2, tl, tm, pos);
  else
    update(v * 2 + 1, tm + 1, tr, pos);
  tree[v].val = sum(tree[v * 2].val, tree[v * 2 + 1].val);
  tree[v].d = sum(tree[v * 2].d, tree[v * 2 + 1].d);
}
int getsum(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (l == tl && r == tr) return tree[v].val;
  push(v);
  int tm = (tl + tr) / 2;
  return sum(getsum(v * 2, tl, tm, l, min(r, tm)),
             getsum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
int getvalue(int v, int tl, int tr, int pos) {
  if (tl == tr) {
    return tree[v].d;
  }
  push(v);
  int tm = (tl + tr) / 2;
  if (pos <= tm) return getvalue(v * 2, tl, tm, pos);
  return getvalue(v * 2 + 1, tm + 1, tr, pos);
}
int main() {
  scanf("%d%d", &x, &q);
  c[1] = x;
  n = 1;
  for (int i = 1; i <= q; i++) {
    int type, v;
    scanf("%d", &type);
    if (type == 1) {
      int p;
      scanf("%d%d", &p, &x);
      n++;
      v = n;
      g[p].push_back(v);
      parent[v] = p;
      c[v] = x;
    } else {
      scanf("%d", &v);
    }
    queries[i] = Query(type, v);
  }
  tcur = 0;
  dfs(1);
  build(1, 1, n);
  update(1, 1, n, 1);
  s[1] = 1;
  for (int i = 1; i <= q; i++) {
    if (queries[i].type == 1) {
      int v = queries[i].v;
      int tmp = s[parent[v]];
      int val = product(tmp + 1, power(tmp, MOD - 2));
      multOnSegment(1, 1, n, lt[parent[v]], rt[parent[v]], val);
      update(1, 1, n, tin[v]);
      s[parent[v]]++;
      s[v]++;
    } else {
      int v = queries[i].v;
      int res = getsum(1, 1, n, lt[v], rt[v]);
      int val;
      if (v == 1)
        val = 1;
      else
        val = getvalue(1, 1, n, tin[parent[v]]);
      mult(res, power(val, MOD - 2));
      printf("%d\n", res);
    }
  }
  return 0;
}