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 = 200005;
const long long MOD = 1e9 + 7;
int n, m, q, tot, opt[N], b[N], d[N];
int sz[N], fa[N], dfn[N], f[N], rr[N];
int v[N], head[N], nxt[N], ni, mi;
long long a[N], s[N * 4], tag[N * 4];
long long MPL(long long a, long long b) {
  return a + b >= MOD ? a + b - MOD : a + b;
}
long long inv(long long a) {
  long long b = MOD - 2, res = 1;
  while (b) {
    if (b % 2) res = res * a % MOD;
    a = a * a % MOD, b >>= 1;
  }
  return res;
}
void dfs(int x) {
  f[rr[x] = dfn[x] = ++tot] = x, sz[x] = 1;
  for (int i = head[x]; i > 0; i = nxt[i]) {
    dfs(v[i]), sz[x] += sz[v[i]];
    rr[x] = rr[v[i]];
  }
}
void build(int x, int l, int r) {
  tag[x] = 1;
  if (l == r) {
    if (l == 1) s[x] = a[f[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r);
  s[x] = s[x << 1] + s[x << 1 | 1];
  if (s[x] >= MOD) s[x] -= MOD;
}
void pushdown(int x, int l, int r) {
  if (tag[x] == 1) return;
  int mid = (l + r) >> 1;
  s[x << 1] = s[x << 1] * tag[x] % MOD;
  s[x << 1 | 1] = s[x << 1 | 1] * tag[x] % MOD;
  tag[x << 1] = tag[x << 1] * tag[x] % MOD;
  tag[x << 1 | 1] = tag[x << 1 | 1] * tag[x] % MOD;
  tag[x] = 1;
}
void add(int x, int l, int r, int k, long long val) {
  if (l == r) {
    s[x] = MPL(s[x], val);
    return;
  }
  pushdown(x, l, r);
  int mid = (l + r) >> 1;
  if (k <= mid)
    add(x << 1, l, mid, k, val);
  else
    add(x << 1 | 1, mid + 1, r, k, val);
  s[x] = s[x << 1] + s[x << 1 | 1];
  if (s[x] >= MOD) s[x] -= MOD;
}
void mult(int x, int l, int r, int L, int R, long long val) {
  if (l >= L && R >= r) {
    s[x] = s[x] * val % MOD;
    tag[x] = tag[x] * val % MOD;
    return;
  }
  pushdown(x, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) mult(x << 1, l, mid, L, R, val);
  if (R > mid) mult(x << 1 | 1, mid + 1, r, L, R, val);
  s[x] = s[x << 1] + s[x << 1 | 1];
  if (s[x] >= MOD) s[x] -= MOD;
}
long long query(int x, int l, int r, int L, int R) {
  if (l >= L && R >= r) return s[x];
  pushdown(x, l, r);
  int mid = (l + r) >> 1;
  long long res = 0;
  if (L <= mid) res += query(x << 1, l, mid, L, R);
  if (R > mid) res += query(x << 1 | 1, mid + 1, r, L, R);
  if (res >= MOD) res -= MOD;
  return res;
}
void prt(int x, int l, int r) {
  cout << x << ' ' << l << ' ' << r << ' ' << s[x] << endl;
  if (l == r) return;
  pushdown(x, l, r);
  int mid = (l + r) >> 1;
  prt(x << 1, l, mid), prt(x << 1 | 1, mid + 1, r);
}
int main() {
  scanf("%d%d", &a[n = 1], &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d", &opt[i]);
    if (opt[i] == 1) {
      ++n, scanf("%d%d", &fa[n], &a[n]);
      nxt[n] = head[fa[n]], head[fa[n]] = v[n] = n;
    } else
      scanf("%d", &b[i - n + 1]);
  }
  dfs(1), build(1, 1, n);
  for (int i = 1; i <= q; i++) {
    if (opt[i] == 2) {
      int x = b[++m];
      if (x == 1)
        printf("%lld\n", s[1]);
      else {
        long long tm =
            inv(query(1, 1, n, dfn[fa[x]], dfn[fa[x]])) * a[fa[x]] % MOD;
        printf("%lld\n", query(1, 1, n, dfn[x], rr[x]) * tm % MOD);
      }
    } else {
      int x = i - m + 1;
      long long tm =
          query(1, 1, n, dfn[fa[x]], dfn[fa[x]]) * inv(a[fa[x]]) % MOD;
      add(1, 1, n, dfn[x], a[x] * tm % MOD), d[fa[x]]++;
      mult(1, 1, n, dfn[fa[x]], rr[fa[x]],
           inv(d[fa[x]]) * (d[fa[x]] + 1) % MOD);
    }
  }
}