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 inf = 987654321;
const long long int INF = 123456789987654321;
const long long int mod = 1000000007;
int V, Q, Vertex;
vector<vector<int> > adj;
struct query {
  int t, p, v;
};
vector<query> qur;
vector<int> tin, tout;
int timer = 0;
void dfs(int now) {
  tin[now] = timer++;
  for (int i = 0; i < adj[now].size(); i++) {
    int nxt = adj[now][i];
    dfs(nxt);
  }
  tout[now] = timer;
}
void get_tin() {
  tin = tout = vector<int>(Vertex, -1);
  dfs(0);
}
long long int pw(long long int x, long long int n) {
  long long int ret = 1;
  while (n) {
    if (n % 2) ret = ret * x % mod;
    x = x * x % mod;
    n /= 2;
  }
  return ret;
}
long long int mod_inv(long long int x) { return pw(x, mod - 2); }
vector<long long int> mod_inv2;
void get_mod_inv2() {
  mod_inv2.resize(Vertex + 1);
  for (int i = 1; i <= Vertex; i++) {
    mod_inv2[i] = mod_inv((long long int)i);
  }
}
struct BIT {
  vector<long long int> tree;
  vector<long long int> lazy;
  void init() {
    tree = vector<long long int>(4 * Vertex, 0);
    lazy = vector<long long int>(4 * Vertex, 1);
  }
  void prop(int l, int r, int n) {
    if (l != r) {
      tree[2 * n] = tree[2 * n] * lazy[n] % mod;
      tree[2 * n + 1] = tree[2 * n + 1] * lazy[n] % mod;
      lazy[2 * n] = lazy[2 * n] * lazy[n] % mod;
      lazy[2 * n + 1] = lazy[2 * n + 1] * lazy[n] % mod;
    }
    lazy[n] = 1;
  }
  void interval_udt(int a, int b, long long int p, int l, int r, int n) {
    if (b < l || r < a) return;
    if (a <= l && r <= b) {
      lazy[n] = lazy[n] * p % mod;
      tree[n] = tree[n] * p % mod;
      return;
    }
    prop(l, r, n);
    int m = (l + r) >> 1;
    interval_udt(a, b, p, l, m, 2 * n);
    interval_udt(a, b, p, m + 1, r, 2 * n + 1);
    tree[n] = (tree[2 * n] + tree[2 * n + 1]) % mod;
  }
  void udt(int idx, long long int val, int l, int r, int n) {
    if (idx < l || r < idx) return;
    if (l == r) {
      tree[n] = val;
      return;
    }
    prop(l, r, n);
    int m = (l + r) >> 1;
    udt(idx, val, l, m, 2 * n);
    udt(idx, val, m + 1, r, 2 * n + 1);
    tree[n] = (tree[2 * n] + tree[2 * n + 1]) % mod;
  }
  long long int qur(int a, int b, int l, int r, int n) {
    if (b < l || r < a) return 0;
    if (a <= l && r <= b) return tree[n];
    prop(l, r, n);
    int m = (l + r) >> 1;
    long long int t1 = qur(a, b, l, m, 2 * n);
    long long int t2 = qur(a, b, m + 1, r, 2 * n + 1);
    return (t1 + t2) % mod;
  }
} bit;
vector<int> chd_cnt;
vector<long long int> value;
void solve() {
  chd_cnt = vector<int>(Vertex, 0);
  chd_cnt[0] = 1;
  int Vertex2 = 1;
  bit.init();
  bit.udt(tin[0], (long long int)V, 0, Vertex - 1, 1);
  value.resize(Vertex);
  value[0] = (long long int)V;
  for (int i = 0; i < Q; i++) {
    int t = qur[i].t, p = qur[i].p, v = qur[i].v;
    if (t == 1) {
      bit.interval_udt(tin[p], tout[p] - 1,
                       (chd_cnt[p] + 1) * mod_inv2[chd_cnt[p]] % mod, 0,
                       Vertex - 1, 1);
      chd_cnt[p]++;
      long long int x = bit.qur(tin[p], tin[p], 0, Vertex - 1, 1);
      bit.udt(tin[Vertex2],
              (((long long int)v * x % mod) * mod_inv(value[p]) % mod), 0,
              Vertex - 1, 1);
      chd_cnt[Vertex2]++;
      value[Vertex2] = (long long int)v;
      Vertex2++;
    }
    if (t == 2) {
      long long int x = bit.qur(tin[p], tin[p], 0, Vertex - 1, 1);
      x = x * mod_inv(value[p]) % mod;
      x = x * mod_inv2[chd_cnt[p]] % mod;
      printf("%I64d\n",
             bit.qur(tin[p], tout[p] - 1, 0, Vertex - 1, 1) * mod_inv(x) % mod);
    }
  }
}
int main() {
  scanf("%d %d", &V, &Q);
  qur.resize(Q);
  adj.push_back(vector<int>());
  Vertex = 1;
  for (int i = 0; i < Q; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int p, v;
      scanf("%d %d", &p, &v);
      p--;
      qur[i] = {t, p, v};
      adj.push_back(vector<int>());
      adj[p].push_back(Vertex);
      Vertex++;
    }
    if (t == 2) {
      int u;
      scanf("%d", &u);
      u--;
      qur[i] = {t, u, -1};
    }
  }
  get_tin();
  get_mod_inv2();
  solve();
}