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;
struct EdgeNode {
  int to, next;
} edge[maxn];
int cnt, head[maxn], fa[maxn], deg[maxn];
void add_edge(int u, int v) {
  edge[cnt].to = v, edge[cnt].next = head[u];
  head[u] = cnt++;
}
struct Query {
  int id, u, v;
} qur[maxn];
int bef[maxn], aft[maxn], dclk;
void dfs(int u) {
  bef[u] = ++dclk;
  for (int k = head[u]; k != -1; k = edge[k].next) dfs(edge[k].to);
  aft[u] = dclk;
}
const long long mod = 1e9 + 7;
long long rev[maxn];
long long pow_mod(long long x, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ans * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}
long long sum[maxn << 2], cof[maxn << 2], lazy[maxn << 2];
void build(int l, int r, int o) {
  sum[o] = 0;
  cof[o] = lazy[o] = 1;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(l, mid, (o << 1));
  build(mid + 1, r, (o << 1 | 1));
}
void pushup(int o) { sum[o] = (sum[(o << 1)] + sum[(o << 1 | 1)]) % mod; }
void fun(int o, long long cl) {
  sum[o] = sum[o] * cl % mod;
  cof[o] = cof[o] * cl % mod;
  lazy[o] = lazy[o] * cl % mod;
}
void pushdown(int o) {
  if (lazy[o] != 1) {
    fun((o << 1), lazy[o]);
    fun((o << 1 | 1), lazy[o]);
    lazy[o] = 1;
  }
}
void addLeaf(int l, int r, int o, int L, long long v) {
  if (l == r) {
    sum[o] = v * cof[o] % mod;
    return;
  }
  pushdown(o);
  int mid = (l + r) / 2;
  if (L <= mid)
    addLeaf(l, mid, (o << 1), L, v);
  else
    addLeaf(mid + 1, r, (o << 1 | 1), L, v);
  pushup(o);
}
void update(int l, int r, int o, int L, int R, long long cl) {
  if (L <= l && r <= R) {
    fun(o, cl);
    return;
  }
  pushdown(o);
  int mid = (l + r) / 2;
  if (L <= mid) update(l, mid, (o << 1), L, R, cl);
  if (R > mid) update(mid + 1, r, (o << 1 | 1), L, R, cl);
  pushup(o);
}
long long querySum(int l, int r, int o, int L, int R) {
  if (L <= l && r <= R) return sum[o];
  pushdown(o);
  int mid = (l + r) / 2;
  long long ans = 0;
  if (L <= mid) ans += querySum(l, mid, (o << 1), L, R);
  if (R > mid) ans += querySum(mid + 1, r, (o << 1 | 1), L, R);
  pushup(o);
  return ans % mod;
}
long long queryCof(int l, int r, int o, int L) {
  if (l == r) return cof[o];
  pushdown(o);
  int mid = (l + r) / 2, ans;
  if (L <= mid)
    ans = queryCof(l, mid, (o << 1), L);
  else
    ans = queryCof(mid + 1, r, (o << 1 | 1), L);
  pushup(o);
  return ans;
}
long long getRev(long long val) {
  if (rev[val] == -1) rev[val] = pow_mod(val, mod - 2);
  return rev[val];
}
void add(int p, long long v) {
  int f = fa[p];
  addLeaf(1, aft[1], 1, bef[p], v);
  long long tmp = ++deg[f];
  tmp = (tmp + 1) * getRev(tmp) % mod;
  update(bef[1], aft[1], 1, bef[f], aft[f], tmp);
}
int main() {
  int v, q;
  scanf("%d%d", &v, &q);
  int cur = 1;
  cnt = 0;
  memset(head, -1, sizeof(head));
  memset(deg, 0, sizeof(deg));
  memset(rev, -1, sizeof(rev));
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &qur[i].id, &qur[i].u);
    if (qur[i].id == 1) {
      scanf("%d", &qur[i].v);
      ++cur;
      fa[cur] = qur[i].u;
      add_edge(qur[i].u, cur);
      qur[i].u = cur;
    }
  }
  dclk = 0;
  dfs(1);
  build(bef[1], aft[1], 1);
  addLeaf(bef[1], aft[1], 1, bef[1], v);
  for (int i = 0; i < q; i++) {
    if (qur[i].id == 1)
      add(qur[i].u, qur[i].v);
    else {
      int u = qur[i].u;
      long long sum = querySum(bef[1], aft[1], 1, bef[u], aft[u]);
      long long cc = queryCof(bef[1], aft[1], 1, bef[u]);
      long long tmp = (deg[u] + 1) * pow_mod(cc, mod - 2) % mod;
      printf("%I64d\n", sum * tmp % mod);
    }
  }
  return 0;
}