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 mod = (int)1e9 + 7;
const int pow2 = (1 << 19);
const int N = (int)4e5 + 10;
int add(int a, int b) {
  a += b;
  if (a < mod) return a;
  return a - mod;
}
int mult(int a, int b) { return (1LL * a * b) % mod; }
int myPow(int a, int k) {
  if (k == 0) return 1;
  if (k & 1) return mult(a, myPow(a, k - 1));
  int t = myPow(a, k / 2);
  return mult(t, t);
}
int rev(int a) { return myPow(a, mod - 2); }
struct SegmentTree {
  int tree[pow2 * 2];
  int d[pow2 * 2];
  SegmentTree() {
    for (int i = 0; i < pow2 * 2; i++) {
      tree[i] = 0;
      d[i] = 1;
    }
  }
  void push(int v, int len) {
    if (d[v] == 1) return;
    tree[2 * v] = mult(tree[2 * v], d[v]);
    d[2 * v] = mult(d[2 * v], d[v]);
    tree[2 * v + 1] = mult(tree[2 * v + 1], d[v]);
    d[2 * v + 1] = mult(d[2 * v + 1], d[v]);
    d[v] = 1;
  }
  void relax(int v) { tree[v] = add(tree[2 * v], tree[2 * v + 1]); }
  void addVal(int pos, int val, int v, int l, int r) {
    if (l == r) {
      tree[v] = add(tree[v], val);
      return;
    }
    push(v, (r - l + 1) / 2);
    int m = (l + r) / 2;
    if (pos <= m)
      addVal(pos, val, 2 * v, l, m);
    else
      addVal(pos, val, 2 * v + 1, m + 1, r);
    relax(v);
  }
  void addVal(int pos, int val) { addVal(pos, val, 1, 0, pow2 - 1); }
  void setVal(int pos, int val, int v, int l, int r) {
    if (l == r) {
      tree[v] = val;
      return;
    }
    push(v, (r - l + 1) / 2);
    int m = (l + r) / 2;
    if (pos <= m)
      setVal(pos, val, 2 * v, l, m);
    else
      setVal(pos, val, 2 * v + 1, m + 1, r);
    relax(v);
  }
  void setVal(int pos, int val) { setVal(pos, val, 1, 0, pow2 - 1); }
  void multSeg(int a, int b, int val, int v, int l, int r) {
    if (l >= a && r <= b) {
      d[v] = mult(d[v], val);
      tree[v] = mult(tree[v], val);
      return;
    }
    if (l > b || r < a) return;
    push(v, (r - l + 1) / 2);
    int m = (l + r) / 2;
    multSeg(a, b, val, 2 * v, l, m);
    multSeg(a, b, val, 2 * v + 1, m + 1, r);
    relax(v);
  }
  void multSeg(int a, int b, int val) { multSeg(a, b, val, 1, 0, pow2 - 1); }
  int getSum(int a, int b, int v, int l, int r) {
    if (l >= a && r <= b) return tree[v];
    if (l > b || r < a) return 0;
    push(v, (r - l + 1) / 2);
    int m = (l + r) / 2;
    return add(getSum(a, b, 2 * v, l, m), getSum(a, b, 2 * v + 1, m + 1, r));
  }
  int getSum(int a, int b) { return getSum(a, b, 1, 0, pow2 - 1); }
  void printPrefix(int len, int v, int l, int r) {
    if (l > len) return;
    if (l == r) {
      42;
      return;
    }
    push(v, (r - l + 1) / 2);
    int m = (l + r) / 2;
    printPrefix(len, 2 * v, l, m);
    printPrefix(len, 2 * v + 1, m + 1, r);
  }
  void printPrefix(int len) {
    printPrefix(len, 1, 0, pow2 - 1);
    42;
  }
};
struct SegmentTreeProd {
  int tree[pow2 * 2];
  SegmentTreeProd() {
    for (int i = 0; i < pow2 * 2; i++) tree[i] = 1;
  }
  void relax(int v) { tree[v] = mult(tree[2 * v], tree[2 * v + 1]); }
  void addVal(int pos, int val, int v, int l, int r) {
    if (l == r) {
      tree[v] = add(tree[v], val);
      return;
    }
    int m = (l + r) / 2;
    if (pos <= m)
      addVal(pos, val, 2 * v, l, m);
    else
      addVal(pos, val, 2 * v + 1, m + 1, r);
    relax(v);
  }
  void addVal(int pos, int val) { addVal(pos, val, 1, 0, pow2 - 1); }
  void setVal(int pos, int val, int v, int l, int r) {
    if (l == r) {
      tree[v] = val;
      return;
    }
    int m = (l + r) / 2;
    if (pos <= m)
      setVal(pos, val, 2 * v, l, m);
    else
      setVal(pos, val, 2 * v + 1, m + 1, r);
    relax(v);
  }
  void setVal(int pos, int val) { setVal(pos, val, 1, 0, pow2 - 1); }
  int getProd(int a, int b, int v, int l, int r) {
    if (l >= a && r <= b) return tree[v];
    if (l > b || r < a) return 1;
    int m = (l + r) / 2;
    return mult(getProd(a, b, 2 * v, l, m), getProd(a, b, 2 * v + 1, m + 1, r));
  }
  int getProd(int a, int b) { return getProd(a, b, 1, 0, pow2 - 1); }
  void printPrefix(int len, int v, int l, int r) {
    if (l > len) return;
    if (l == r) {
      42;
      return;
    }
    int m = (l + r) / 2;
    printPrefix(len, 2 * v, l, m);
    printPrefix(len, 2 * v + 1, m + 1, r);
  }
  void printPrefix(int len) {
    printPrefix(len, 1, 0, pow2 - 1);
    42;
  }
};
int type[N];
int qA[N], qB[N], qC[N];
int value[N];
vector<int> g[N];
int posIn[N], posOut[N];
int inStart[N], inEnd[N];
int onlyIn[N];
int tinE[N], toutE[N];
int degs[N];
int tme = 0;
int inTme = 0;
int q;
SegmentTreeProd treeIn, treeOut;
SegmentTree ans;
void dfs(int v) {
  inStart[v] = inTme;
  onlyIn[inTme++] = v;
  posIn[v] = tme;
  tinE[tme++] = v;
  for (int to : g[v]) {
    dfs(to);
  }
  posOut[v] = tme;
  toutE[tme++] = v;
  inEnd[v] = inTme - 1;
}
int getDegOnPath(int v) {
  return mult(treeIn.getProd(0, posIn[v]), rev(treeOut.getProd(0, posIn[v])));
}
void changeDeg(int v, int d) {
  degs[v] = d;
  treeIn.setVal(posIn[v], d);
  treeOut.setVal(posOut[v], d);
}
void connect(int p, int v) {
  int c = mult(add(degs[p], 1), rev(degs[p]));
  ans.multSeg(inStart[p], inEnd[p], c);
  changeDeg(v, degs[v] + 1);
  changeDeg(p, degs[p] + 1);
  ans.setVal(inStart[v], mult(value[v], getDegOnPath(v)));
}
int getValue(int v) {
  int res = ans.getSum(inStart[v], inEnd[v]);
  res = mult(res, mult(rev(getDegOnPath(v)), degs[v]));
  return res;
}
int main() {
  scanf("%d%d", &value[0], &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &type[i]);
    scanf("%d", &qA[i]);
    qA[i]--;
    if (type[i] == 1) scanf("%d", &qB[i]);
  }
  int id = 1;
  for (int i = 0; i < q; i++) {
    if (type[i] == 1) {
      g[qA[i]].push_back(id);
      value[id] = qB[i];
      qC[i] = id;
      id++;
    }
  }
  dfs(0);
  changeDeg(0, 1);
  ans.setVal(inStart[0], value[0]);
  for (int i = 0; i < q; i++) {
    if (type[i] == 1)
      connect(qA[i], qC[i]);
    else
      printf("%d\n", getValue(qA[i]));
  }
  return 0;
}