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 = 2e5 + 10;
const long long INF = 1e9 + 19;
const int MOD = 1e9 + 7;
struct Query {
  int type, v, u, val;
  void read() {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%d", &v, &val);
    } else
      scanf("%d", &v);
    v--;
  }
};
void mul(int& a, int b) { a = (a * 1ll * b) % MOD; }
struct SegTree {
  vector<int> data;
  vector<int> upd;
  int sz;
  void init(int n) {
    sz = n;
    data.resize(sz * 4);
    upd.assign(sz * 4, 1);
  }
  void push(int v) {
    if (upd[v] != 1) {
      mul(upd[v * 2 + 1], upd[v]);
      mul(upd[v * 2 + 2], upd[v]);
      mul(data[v * 2 + 1], upd[v]);
      mul(data[v * 2 + 2], upd[v]);
      upd[v] = 1;
    }
  }
  int getSum(int v, int ll, int rr, int l, int r) {
    if (ll >= r || l >= rr) return 0;
    if (l <= ll && rr <= r) return data[v];
    push(v);
    int res = (getSum(v * 2 + 1, ll, (ll + rr) / 2, l, r) +
               getSum(v * 2 + 2, (ll + rr) / 2, rr, l, r));
    if (res >= MOD) res -= MOD;
    return res;
  }
  void setPos(int v, int ll, int rr, int pos, int val) {
    if (pos < ll || rr <= pos) return;
    if (ll + 1 == rr) {
      data[v] = val;
      return;
    }
    push(v);
    setPos(v * 2 + 1, ll, (ll + rr) / 2, pos, val);
    setPos(v * 2 + 2, (ll + rr) / 2, rr, pos, val);
    data[v] = (data[v * 2 + 1] + data[v * 2 + 2]) % MOD;
  }
  void mulSeg(int v, int ll, int rr, int l, int r, int val) {
    if (l >= rr || ll >= r) return;
    if (l <= ll && rr <= r) {
      mul(data[v], val);
      mul(upd[v], val);
      return;
    }
    push(v);
    mulSeg(v * 2 + 1, ll, (ll + rr) / 2, l, r, val);
    mulSeg(v * 2 + 2, (ll + rr) / 2, rr, l, r, val);
    data[v] = (data[v * 2 + 1] + data[v * 2 + 2]) % MOD;
  }
};
int val[N];
Query q[N];
vector<int> e[N];
int n;
int tin[N];
int tout[N];
int tmr;
int sz[N];
int par[N];
int cur = 1;
int rev(int a, int m) {
  if (a == 0) return 0;
  int x = (1 - rev(m % a, a) * 1ll * m) / a;
  if (x < 0) x += m;
  if (x >= m) x -= m;
  return x;
}
void read() {
  scanf("%d%d", &val[0], &n);
  for (int i = 0; i < n; i++) {
    q[i].read();
  }
}
void dfs(int v) {
  tin[v] = tmr++;
  for (auto u : e[v]) {
    par[u] = v;
    dfs(u);
  }
  tout[v] = tmr;
}
SegTree tree;
int getMulRoot(int v) {
  int tmp = tree.getSum(0, 0, cur, tin[v], tin[v] + 1);
  int rem = rev(val[v], MOD);
  mul(tmp, rem);
  return tmp;
}
void solve() {
  for (int i = 0; i < n; i++) {
    if (q[i].type == 1) {
      e[q[i].v].push_back(cur);
      q[i].u = cur;
      val[cur] = q[i].val;
      cur++;
    }
  }
  for (int i = 0; i < cur; i++) sz[i] = 1;
  dfs(0);
  tree.init(cur);
  tree.setPos(0, 0, cur, tin[0], val[0]);
  for (int i = 0; i < n; i++) {
    if (q[i].type == 1) {
      int par = q[i].v;
      int v = q[i].u;
      int r = rev(sz[par], MOD);
      tree.mulSeg(0, 0, cur, tin[par], tout[par], r);
      tree.setPos(0, 0, cur, tin[v], val[v] * 1ll * getMulRoot(par) % MOD);
      sz[par]++;
      tree.mulSeg(0, 0, cur, tin[par], tout[par], sz[par]);
    } else {
      int v = q[i].v;
      int val = tree.getSum(0, 0, cur, tin[v], tout[v]);
      int tmp = 1;
      if (v != 0) tmp = getMulRoot(par[v]);
      int rem = rev(tmp, MOD);
      mul(val, rem);
      printf("%d\n", (int)val);
    }
  }
}
void stress() {}
int main() {
  if (1) {
    int k = 1;
    for (int tt = 0; tt < k; tt++) {
      read();
      solve();
    }
  } else {
    stress();
  }
  return 0;
}