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 = 200000 + 10;
const int MOD = 1000000007;
int timer;
int val[maxn], dfn[maxn], last[maxn], n, q, fa[maxn];
vector<int> g[maxn];
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
struct Node {
  int type, p, v;
  void init() {
    type = read();
    if (type == 1)
      p = read(), v = read();
    else
      v = read();
  }
} query[maxn];
struct Tree {
  int sum, sz;
} tree[maxn * 4];
int deg[maxn];
void dfs(int u, int pre) {
  dfn[u] = ++timer;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != pre) dfs(v, u);
  }
  last[u] = timer;
}
inline void push_up(int o) {
  int lson = o << 1, rson = lson | 1;
  tree[o].sum = (tree[lson].sum + tree[rson].sum) % MOD;
}
inline void push_down(int o) {
  if (tree[o].sz != 1) {
    int tmp = tree[o].sz, lson = o << 1, rson = lson | 1;
    tree[o].sz = 1;
    tree[lson].sum = (long long)tree[lson].sum * tmp % MOD;
    tree[lson].sz = (long long)tree[lson].sz * tmp % MOD;
    tree[rson].sum = (long long)tree[rson].sum * tmp % MOD;
    tree[rson].sz = (long long)tree[rson].sz * tmp % MOD;
  }
}
void Build(int o, int l, int r) {
  tree[o].sum = 0;
  tree[o].sz = 1;
  if (l == r) return;
  int mid = (l + r) >> 1, lson = o << 1, rson = lson | 1;
  Build(lson, l, mid);
  Build(rson, mid + 1, r);
}
void Modify(int o, int l, int r, int ql, int qr, int w) {
  if (ql <= l && r <= qr) {
    tree[o].sz = (long long)tree[o].sz * w % MOD;
    tree[o].sum = (long long)tree[o].sum * w % MOD;
    return;
  }
  int mid = (l + r) >> 1, lson = o << 1, rson = lson | 1;
  push_down(o);
  if (ql <= mid) Modify(lson, l, mid, ql, qr, w);
  if (qr > mid) Modify(rson, mid + 1, r, ql, qr, w);
  push_up(o);
}
void Insert(int o, int l, int r, int v, int w) {
  if (l == r) {
    tree[o].sum = (tree[o].sum + w) % MOD;
    return;
  }
  push_down(o);
  int mid = (l + r) >> 1, lson = o << 1, rson = lson | 1;
  if (v <= mid)
    Insert(lson, l, mid, v, w);
  else
    Insert(rson, mid + 1, r, v, w);
  push_up(o);
}
int Get_sum(int o, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return tree[o].sum;
  int mid = (l + r) >> 1, lson = o << 1, rson = lson | 1, ans = 0;
  push_down(o);
  if (ql <= mid) ans = (ans + Get_sum(lson, l, mid, ql, qr)) % MOD;
  if (qr > mid) ans = (ans + Get_sum(rson, mid + 1, r, ql, qr)) % MOD;
  push_up(o);
  return ans;
}
int Get_sz(int o, int l, int r, int pos) {
  if (l == r) return tree[o].sz;
  int mid = (l + r) >> 1, lson = o << 1, rson = lson | 1, ans;
  push_down(o);
  if (pos <= mid)
    ans = Get_sz(lson, l, mid, pos);
  else
    ans = Get_sz(rson, mid + 1, r, pos);
  push_up(o);
  return ans;
}
inline int power(int a, int b) {
  int res = 1, base = a;
  while (b) {
    if (b & 1) res = (long long)res * base % MOD;
    base = (long long)base * base % MOD;
    b >>= 1;
  }
  return res;
}
int main() {
  val[1] = read(), q = read();
  n = deg[1] = 1;
  for (int i = 1; i <= q; i++) {
    query[i].init();
    if (query[i].type == 1) {
      g[query[i].p].push_back(++n);
      val[n] = query[i].v;
      fa[n] = query[i].p;
    }
  }
  dfs(1, 0);
  Build(1, 1, n);
  Insert(1, 1, n, dfn[1], val[1]);
  int cur = 1;
  for (int i = 1; i <= q; i++)
    if (query[i].type == 1) {
      cur++;
      int p = query[i].p, v = query[i].v;
      Modify(1, 1, n, dfn[p], last[p],
             (long long)(1 + deg[p]) * power(deg[p], MOD - 2) % MOD);
      deg[p]++;
      deg[cur] = 1;
      Insert(1, 1, n, dfn[cur], (long long)Get_sz(1, 1, n, dfn[cur]) * v % MOD);
    } else {
      int v = query[i].v;
      int ans = Get_sum(1, 1, n, dfn[v], last[v]);
      if (v != 1)
        ans =
            (long long)ans * power(Get_sz(1, 1, n, dfn[fa[v]]), MOD - 2) % MOD;
      printf("%d\n", ans);
    }
  return 0;
}