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 maxn = 2e5 + 10;
const int jyb = 1e9 + 7;
struct edge {
  int v, next;
} e[maxn];
int h[maxn], num;
void build_edge(int u, int v) {
  num++;
  e[num].v = v;
  e[num].next = h[u];
  h[u] = num;
}
struct Query {
  int c, x, y;
} Q[maxn];
struct node {
  int l, r, x, lazy;
} t[maxn << 1];
int tot;
int n, q;
int w[maxn], fa[maxn], p[maxn];
int indexx, in[maxn], out[maxn];
int qpow(int x, int y) {
  int res;
  for (res = 1; y; y >>= 1) {
    if (y & 1) res = 1ll * res * x % jyb;
    x = 1ll * x * x % jyb;
  }
  return res;
}
void dfs(int x) {
  in[x] = ++indexx;
  p[x] = 1;
  for (int i = h[x]; i; i = e[i].next) dfs(e[i].v), fa[e[i].v] = x;
  out[x] = indexx;
}
void build(int p, int l, int r) {
  int mid = (l + r) >> 1;
  if (l == r) {
    t[p].x = w[l];
    t[p].lazy = 1;
    return;
  }
  t[p].l = ++tot;
  t[p].r = ++tot;
  build(t[p].l, l, mid);
  build(t[p].r, mid + 1, r);
  t[p].x = (t[t[p].r].x + t[t[p].l].x) % jyb;
  t[p].lazy = 1;
}
void push_down(int p, int lazy) {
  t[p].lazy = 1ll * lazy * t[p].lazy % jyb;
  t[p].x = 1ll * t[p].x * lazy % jyb;
}
int query(int p, int l, int r, int L, int R) {
  int mid = (l + r) >> 1;
  if (L == l && R == r) return t[p].x;
  if (t[p].lazy != 1) {
    push_down(t[p].l, t[p].lazy);
    push_down(t[p].r, t[p].lazy);
    t[p].lazy = 1;
  }
  if (R <= mid)
    return query(t[p].l, l, mid, L, R);
  else if (L > mid)
    return query(t[p].r, mid + 1, r, L, R);
  else
    return (query(t[p].l, l, mid, L, mid) +
            query(t[p].r, mid + 1, r, mid + 1, R)) %
           jyb;
}
void add(int p, int l, int r, int pos, int c) {
  int mid = (l + r) >> 1;
  if (l == r) {
    t[p].x = c;
    return;
  }
  if (t[p].lazy != 1) {
    push_down(t[p].l, t[p].lazy);
    push_down(t[p].r, t[p].lazy);
    t[p].lazy = 1;
  }
  if (pos <= mid)
    add(t[p].l, l, mid, pos, c);
  else
    add(t[p].r, mid + 1, r, pos, c);
  t[p].x = (t[t[p].l].x + t[t[p].r].x) % jyb;
}
void change(int p, int l, int r, int L, int R, int c) {
  int mid = (l + r) >> 1;
  if (l == L && R == r) {
    t[p].x = 1ll * t[p].x * c % jyb;
    t[p].lazy = 1ll * t[p].lazy * c % jyb;
    return;
  }
  if (t[p].lazy != 1) {
    push_down(t[p].l, t[p].lazy);
    push_down(t[p].r, t[p].lazy);
    t[p].lazy = 1;
  }
  if (R <= mid)
    change(t[p].l, l, mid, L, R, c);
  else if (L > mid)
    change(t[p].r, mid + 1, r, L, R, c);
  else {
    change(t[p].l, l, mid, L, mid, c);
    change(t[p].r, mid + 1, r, mid + 1, R, c);
  }
  t[p].x = (t[t[p].l].x + t[t[p].r].x) % jyb;
}
int main() {
  scanf("%d%d", &w[1], &q);
  int now = 1;
  for (int i = 1; i <= q; i++) {
    scanf("%d", &Q[i].c);
    scanf("%d", &Q[i].x);
    if (Q[i].c == 1) {
      now++;
      scanf("%d", &Q[i].y);
      build_edge(Q[i].x, now);
    }
  }
  n = now;
  dfs(1);
  build(0, 1, n);
  now = 1;
  for (int i = 1; i <= q; i++) {
    int x = Q[i].x;
    int inv;
    if (Q[i].c == 2) {
      int ans = query(0, 1, n, in[x], out[x]);
      if (x == 1)
        inv = 1;
      else {
        int faa = fa[x];
        inv = query(0, 1, n, in[faa], in[faa]);
        inv = 1ll * qpow(w[faa], jyb - 2) * inv % jyb;
        inv = qpow(inv, jyb - 2);
      }
      printf("%d\n", 1ll * ans * inv % jyb);
    } else {
      now++;
      int y = Q[i].y;
      w[now] = y;
      int ans = query(0, 1, n, in[x], in[x]);
      inv = qpow(w[x], jyb - 2);
      inv = 1ll * ans * inv % jyb;
      ans = 1ll * inv * w[now] % jyb;
      add(0, 1, n, in[now], ans);
      int P = p[x]++;
      int c = 1ll * qpow(P, jyb - 2) * p[x] % jyb;
      change(0, 1, n, in[x], out[x], c);
    }
  }
  return 0;
}