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;
int sum[800005], lazy[800005];
int st[200005], en[200005], t, cnt[200005];
int tp[200005], u[200005], num[200005], fa[200005], v[200005];
int lst[200005], to[400005], pre[400005], tot;
inline void add_edge(int u, int v) {
  to[tot] = v;
  pre[tot] = lst[u];
  lst[u] = tot++;
}
inline long long quick_pow(long long a, int n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    n >>= 1;
  }
  return res;
}
inline void push_up(int u) {
  sum[u] = (sum[u << 1] + sum[u << 1 | 1]) % 1000000007;
}
inline void push_down(int u) {
  if (lazy[u] == 1) return;
  lazy[u << 1] = (long long)lazy[u << 1] * lazy[u] % 1000000007;
  lazy[u << 1 | 1] = (long long)lazy[u << 1 | 1] * lazy[u] % 1000000007;
  sum[u << 1] = (long long)sum[u << 1] * lazy[u] % 1000000007;
  sum[u << 1 | 1] = (long long)sum[u << 1 | 1] * lazy[u] % 1000000007;
  lazy[u] = 1;
}
void modify(int u, int l, int r, int pos, int x) {
  if (l == r) {
    sum[u] = x;
    return;
  }
  push_down(u);
  int m = l + r >> 1;
  if (pos <= m)
    modify(u << 1, l, m, pos, x);
  else
    modify(u << 1 | 1, m + 1, r, pos, x);
  push_up(u);
}
void modify(int u, int l, int r, int L, int R, int x) {
  if (L <= l && r <= R) {
    lazy[u] = (long long)lazy[u] * x % 1000000007;
    sum[u] = (long long)sum[u] * x % 1000000007;
    return;
  }
  push_down(u);
  int m = l + r >> 1;
  if (L <= m) modify(u << 1, l, m, L, R, x);
  if (m < R) modify(u << 1 | 1, m + 1, r, L, R, x);
  push_up(u);
}
int query(int u, int l, int r, int L, int R) {
  if (L <= l && r <= R) return sum[u];
  push_down(u);
  int m = l + r >> 1, res = 0;
  if (L <= m) res = (res + query(u << 1, l, m, L, R)) % 1000000007;
  if (m < R) res = (res + query(u << 1 | 1, m + 1, r, L, R)) % 1000000007;
  return res;
}
void dfs(int u) {
  st[u] = t++;
  for (int i = lst[u]; ~i; i = pre[i]) dfs(to[i]);
  en[u] = t;
}
int main() {
  memset(lst, -1, sizeof(lst));
  int q, n = 1;
  scanf("%d%d", v, &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", tp + i, u + i);
    u[i]--;
    if (tp[i] == 1) {
      scanf("%d", v + n);
      num[i] = n;
      fa[n] = u[i];
      add_edge(u[i], n++);
    }
  }
  dfs(0);
  for (int i = 0; i < 800005; i++) lazy[i] = 1;
  modify(1, 0, n - 1, 0, v[0]);
  for (int i = 0; i < q; i++) {
    if (tp[i] - 1) {
      int ans = query(1, 0, n - 1, st[u[i]], en[u[i]] - 1);
      if (u[i]) {
        int res = query(1, 0, n - 1, st[fa[u[i]]], st[fa[u[i]]]);
        ans =
            quick_pow(quick_pow(v[fa[u[i]]], 1000000007 - 2) * res % 1000000007,
                      1000000007 - 2) *
            ans % 1000000007;
      }
      printf("%d\n", ans);
    } else {
      cnt[u[i]]++;
      modify(
          1, 0, n - 1, st[u[i]], en[u[i]] - 1,
          quick_pow(cnt[u[i]], 1000000007 - 2) * (cnt[u[i]] + 1) % 1000000007);
      modify(1, 0, n - 1, st[num[i]],
             quick_pow(v[u[i]], 1000000007 - 2) *
                 query(1, 0, n - 1, st[u[i]], st[u[i]]) % 1000000007 *
                 v[num[i]] % 1000000007);
    }
  }
  return 0;
}