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;
long long t, n, m, u, v, q, r, ql, qr, k, l, s, w, z, d, b, p;
const int N = 2e5 + 500;
;
const int LN = 19;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 52LL;
vector<int> adj[N];
int val[N], type[N], L[N], R[N], tin[N], sz[N], X[N];
int tree[4 * N], lazy[4 * N];
inline long long PowerMod(long long a, long long p,
                          long long mod = 1000000007) {
  long long ret = 1;
  a %= mod;
  while (p > 0) {
    if (p & 1) {
      ret *= a;
      ret %= mod;
    }
    a *= a;
    a %= mod;
    p >>= 1LL;
  }
  return ret;
}
int H = 0;
void init(int l, int r, int i) {
  if (l == r) {
    lazy[i] = 1;
    tree[i] = val[l];
    return;
  }
  int mid = (l + r) / 2;
  init(l, mid, i + 1 + i);
  init(mid + 1, r, i + 2 + i);
  tree[i] = tree[i + 1 + i] + tree[i + 2 + i];
  lazy[i] = 1;
}
inline void push(int i) {
  if (lazy[i] == 1) return;
  for (int j = 1; j <= 2; ++j) {
    lazy[i + j + i] = (1LL * lazy[i + j + i] * lazy[i]) % mod;
    tree[i + j + i] = (1LL * tree[i + j + i] * lazy[i]) % mod;
  }
  lazy[i] = 1;
}
void modify(int l, int r, int i, int rl, int rr, int mul) {
  if (rl <= l && r <= rr) {
    lazy[i] = (1LL * lazy[i] * mul) % mod;
    tree[i] = (1LL * tree[i] * mul) % mod;
    return;
  }
  if (l > rr || rl > r) return;
  push(i);
  int mid = (l + r) / 2;
  modify(l, mid, i + 1 + i, rl, rr, mul);
  modify(mid + 1, r, i + 2 + i, rl, rr, mul);
  tree[i] = (tree[i + 1 + i] + tree[i + 2 + i]);
  if (tree[i] >= mod) tree[i] -= mod;
}
int query(int l, int r, int i, int rl, int rr) {
  if (rl <= l && r <= rr) {
    return tree[i];
  }
  if (l > rr || rl > r) return 0;
  push(i);
  int mid = (l + r) / 2;
  int x = query(l, mid, i + 1 + i, rl, rr);
  int y = query(mid + 1, r, i + 2 + i, rl, rr);
  if (x + y >= mod)
    return x + y - mod;
  else
    return x + y;
}
void modify(int l, int r, int i, int rr, int x) {
  if (l == r) {
    tree[i] = x;
    lazy[i] = 1;
    return;
  }
  push(i);
  int mid = (l + r) / 2;
  if (rr <= mid)
    modify(l, mid, i + 1 + i, rr, x);
  else
    modify(mid + 1, r, i + 2 + i, rr, x);
  tree[i] = (tree[i + 1 + i] + tree[i + 2 + i]);
  if (tree[i] >= mod) tree[i] -= mod;
}
void dfs(int v) {
  tin[v] = ++H;
  X[H] = v;
  sz[v] = 1;
  for (int u : adj[v]) {
    dfs(u);
    sz[v] += sz[u];
  }
}
int xs[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> val[1] >> q;
  q++;
  init(1, q, 0);
  int pos = 2;
  for (int i = 1; i < q; ++i) {
    cin >> type[i];
    if (type[i] == 1) {
      cin >> L[i] >> R[i];
      adj[L[i]].push_back(pos++);
      val[pos - 1] = R[i];
    } else {
      cin >> L[i];
    }
  }
  dfs(1);
  pos = 2;
  for (int i = 1; i < q; ++i) {
    if (type[i] == 1) {
      v = L[i];
      xs[L[i]]++;
      modify(1, q, 0, tin[v], tin[v] + sz[v] - 1,
             (1LL * (xs[L[i]] + 1) * (PowerMod(xs[L[i]], mod - 2))) % mod);
      int x = (1LL * val[pos] * query(1, q, 0, tin[v], tin[v])) % mod;
      modify(1, q, 0, tin[pos], (1LL * x * PowerMod(val[v], mod - 2)) % mod);
      pos++;
    } else {
      v = L[i];
      int sol = query(1, q, 0, tin[v], tin[v] + sz[v] - 1);
      sol = (1LL * sol * (xs[v] + 1)) % mod;
      sol = (1LL * sol * (val[v])) % mod;
      sol =
          (1LL * sol * PowerMod(query(1, q, 0, tin[v], tin[v]), mod - 2)) % mod;
      cout << sol << '\n';
    }
  }
  return 0;
}