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 MX = 4e5 + 5, MXX = 23;
const long long mod = 1e9 + 7, inf = 1e18 + 6;
int n = 1, w[MX], ln[MX], q[MX];
vector<int> G[MX];
int multi(int x, int y) { return (1ll * x * y) % mod; }
int pw(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = multi(a, a))
    if (b & 1) ans = multi(ans, a);
  return ans;
}
int in, st[MX], sz[MX];
void pre_dfs(int u) {
  st[u] = in++;
  sz[u] = 1;
  for (auto v : G[u]) pre_dfs(v), sz[u] += sz[v];
}
int fc[MX << 1], sm[MX << 1], rm[MX << 1];
void pre(int u = 1, int l = 0, int r = n) {
  fc[u] = rm[u] = 1;
  if (r - l < 2) {
    if (!l) sm[u] = w[0];
    return;
  }
  int md = (l + r + 1) >> 1;
  pre(u << 1, l, md), pre(u << 1 | 1, md, r);
  sm[u] = sm[u << 1];
}
void clean(int u) {
  if (rm[u] == 1) return;
  sm[u] = multi(sm[u], rm[u]);
  fc[u] = multi(fc[u], rm[u]);
  for (auto c : {u << 1, u << 1 | 1})
    if (c < (MX << 1)) rm[c] = multi(rm[c], rm[u]);
  rm[u] = 1;
}
int d;
int ask(int st, int en, int u = 1, int l = 0, int r = n) {
  clean(u);
  if (en <= l || r <= st) return 0;
  if (st == l && r - l < 2) {
    d = fc[u];
    return sm[u];
  }
  if (st < l && r <= en) return sm[u];
  int md = (l + r + 1) >> 1;
  return (ask(st, en, u << 1, l, md) + ask(st, en, u << 1 | 1, md, r)) % mod;
}
void put(int pnt, int v, int u = 1, int l = 0, int r = n) {
  clean(u);
  if (r - l < 2) {
    sm[u] = multi(fc[u], v);
    return;
  }
  int md = (l + r + 1) >> 1;
  if (pnt < md)
    put(pnt, v, u << 1, l, md);
  else
    put(pnt, v, u << 1 | 1, md, r);
  clean(u << 1), clean(u << 1 | 1);
  sm[u] = (sm[u << 1] + sm[u << 1 | 1]) % mod;
}
void add(int st, int en, int v, int u = 1, int l = 0, int r = n) {
  clean(u);
  if (en <= l || r <= st) return;
  if (st <= l && r <= en) {
    rm[u] = v;
    clean(u);
    return;
  }
  int md = (l + r + 1) >> 1;
  add(st, en, v, u << 1, l, md), add(st, en, v, u << 1 | 1, md, r);
  sm[u] = (sm[u << 1] + sm[u << 1 | 1]) % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(9);
  int T;
  cin >> w[0] >> T;
  for (int i = 0; i < T; ++i) {
    int typ;
    cin >> typ;
    if (typ == 1) {
      cin >> q[i] >> w[n];
      G[q[i] - 1].push_back(n++);
    } else
      cin >> q[i], q[i] = -q[i];
  }
  pre_dfs(0);
  pre();
  for (int i = 0; i < n; ++i) ln[i] = 1;
  int cnt = 1;
  for (int i = 0; i < T; ++i) {
    if (q[i] > 0) {
      int u = q[i] - 1;
      ++ln[u];
      add(st[u], st[u] + sz[u], multi(ln[u], pw(ln[u] - 1, mod - 2)));
      put(st[cnt], w[cnt]);
      ++cnt;
    } else {
      int u = -q[i] - 1;
      int ans = ask(st[u], st[u] + sz[u]);
      cout << multi(ans, multi(pw(d, mod - 2), ln[u])) << "\n";
    }
  }
  return 0;
}