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 int MOD = 1e9 + 7;
int n = 1, q;
int qc[N], qu[N];
int val[N], L[N], R[N], ch[N];
long long st[N << 2], lz[N << 2];
vector<int> adj[N];
long long inverse(long long b) {
  b %= MOD;
  int e = MOD - 2;
  long long a = 1;
  while (e) {
    if (e & 1) a = (a * b) % MOD;
    b = (b * b) % MOD;
    e >>= 1;
  }
  return a;
}
void dfs(int u) {
  static int id = 0;
  L[u] = id++;
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    dfs(v);
  }
  R[u] = id - 1;
}
void push(int p, int L, int R) {
  if (lz[p] != 1) {
    st[p] = (st[p] * lz[p]) % MOD;
    if (L != R) {
      lz[(p << 1)] = (lz[(p << 1)] * lz[p]) % MOD;
      lz[(p << 1) | 1] = (lz[(p << 1) | 1] * lz[p]) % MOD;
    }
    lz[p] = 1;
  }
}
void pull(int p) { st[p] = (st[(p << 1)] + st[(p << 1) | 1]) % MOD; }
long long query(int a, int b, int p = 1, int L = 0, int R = n - 1) {
  push(p, L, R);
  if (b < L || R < a) return 0;
  if (a <= L && R <= b) return st[p];
  long long q = (query(a, b, (p << 1), L, ((L + R) >> 1)) +
                 query(a, b, (p << 1) | 1, ((L + R) >> 1) + 1, R)) %
                MOD;
  pull(p);
  return q;
}
void update(int i, long long x, int p = 1, int L = 0, int R = n - 1) {
  push(p, L, R);
  if (i < L || R < i) return;
  if (L == R) {
    st[p] = x;
    return;
  }
  update(i, x, (p << 1), L, ((L + R) >> 1));
  update(i, x, (p << 1) | 1, ((L + R) >> 1) + 1, R);
  pull(p);
}
void multiply(int a, int b, long long x, int p = 1, int L = 0, int R = n - 1) {
  push(p, L, R);
  if (b < L || R < a) return;
  if (a <= L && R <= b) {
    lz[p] = x;
    push(p, L, R);
    return;
  }
  multiply(a, b, x, (p << 1), L, ((L + R) >> 1));
  multiply(a, b, x, (p << 1) | 1, ((L + R) >> 1) + 1, R);
  pull(p);
}
int main() {
  scanf("%d%d", &val[0], &q);
  n = 1;
  for (int i = 0; i < q; ++i) {
    scanf("%d%d", qc + i, qu + i);
    --qu[i];
    if (qc[i] == 1) {
      adj[qu[i]].push_back(n);
      scanf("%d", &val[n++]);
    }
  }
  dfs(0);
  for (int i = 0; i < (N << 2); ++i) lz[i] = 1;
  update(0, val[0]);
  for (int i = 0; i < q; ++i) {
    int u = qu[i];
    if (qc[i] == 1) {
      int v = adj[u][ch[u]++];
      multiply(L[u], R[u], 1LL * (ch[u] + 1) * inverse(ch[u]) % MOD);
      long long mv = query(L[u], L[u]) * inverse(val[u]) % MOD;
      update(L[v], mv * val[v] % MOD);
    } else {
      long long q = query(L[u], R[u]);
      if (u == 0)
        printf("%I64d\n", q);
      else {
        long long scale =
            1LL * (ch[u] + 1) * val[u] % MOD * inverse(query(L[u], L[u])) % MOD;
        printf("%I64d\n", (q * scale % MOD));
      }
    }
  }
}