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 mod = 1000000007;
long long pw(long long a, long long p) {
  if (p == 0) return 1;
  long long r = pw(a, p / 2);
  r = r * r;
  r %= mod;
  if (p % 2 == 1) {
    return (a * r) % mod;
  }
  return r;
}
struct S {
  long long val, lazy;
  S() {
    val = 0;
    lazy = 1;
  }
};
S tree[1000000];
S join(S L, S R) {
  S res;
  res.val = L.val + R.val;
  res.val %= mod;
  res.lazy = 1;
  return res;
}
void mul(int i, int l, int r, int a, int b, long long s) {
  if (l > r) {
    tree[i] = S();
    return;
  }
  if (a > r || b < l) {
    return;
  }
  if (l >= a && b >= r) {
    tree[i].val *= s;
    tree[i].val %= mod;
    tree[i].lazy *= s;
    tree[i].lazy %= mod;
    return;
  }
  if (tree[i].lazy > 1) {
    mul(i * 2 + 1, l, (l + r) / 2, l, (l + r) / 2, tree[i].lazy);
    mul(i * 2 + 2, (l + r) / 2 + 1, r, (l + r) / 2 + 1, r, tree[i].lazy);
    tree[i].lazy = 1;
  }
  mul(i * 2 + 1, l, (l + r) / 2, a, b, s);
  mul(i * 2 + 2, (l + r) / 2 + 1, r, a, b, s);
  tree[i] = join(tree[i * 2 + 1], tree[i * 2 + 2]);
}
S add(int i, int l, int r, int x, long long val) {
  if (l > r) {
    tree[i] = S();
    return tree[i];
  }
  if (x > r || x < l) {
    return tree[i];
  }
  if (l == r) {
    tree[i].val = tree[i].lazy * val;
    tree[i].val %= mod;
    return tree[i];
  }
  if (tree[i].lazy > 1) {
    mul(i * 2 + 1, l, (l + r) / 2, l, (l + r) / 2, tree[i].lazy);
    mul(i * 2 + 2, (l + r) / 2 + 1, r, (l + r) / 2 + 1, r, tree[i].lazy);
    tree[i].lazy = 1;
  }
  S L = add(i * 2 + 1, l, (l + r) / 2, x, val);
  S R = add(i * 2 + 2, (l + r) / 2 + 1, r, x, val);
  tree[i] = join(L, R);
  return tree[i];
}
S get(int i, int l, int r, int a, int b) {
  if (l >= a && r <= b) {
    return tree[i];
  }
  if (l > b || r < a) {
    S ret;
    return ret;
  }
  if (tree[i].lazy > 1) {
    mul(i * 2 + 1, l, (l + r) / 2, l, (l + r) / 2, tree[i].lazy);
    mul(i * 2 + 2, (l + r) / 2 + 1, r, (l + r) / 2 + 1, r, tree[i].lazy);
    tree[i].lazy = 1;
  }
  S L = get(i * 2 + 1, l, (l + r) / 2, a, b);
  S R = get(i * 2 + 2, (l + r) / 2 + 1, r, a, b);
  S ret = join(L, R);
  return ret;
}
S getMul(int i, int l, int r, int a) {
  if (l > a || r < a) {
    S ret;
    return ret;
  }
  if (l == r) {
    return tree[i];
  }
  if (tree[i].lazy > 1) {
    mul(i * 2 + 1, l, (l + r) / 2, l, (l + r) / 2, tree[i].lazy);
    mul(i * 2 + 2, (l + r) / 2 + 1, r, (l + r) / 2 + 1, r, tree[i].lazy);
    tree[i].lazy = 1;
  }
  if (a <= (l + r) / 2) return getMul(i * 2 + 1, l, (l + r) / 2, a);
  return getMul(i * 2 + 2, (l + r) / 2 + 1, r, a);
}
int v[200005];
int in[200005];
int out[200005];
int n;
vector<int> tr[200005];
int ch[200005];
int par[200005];
struct qu {
  int com, u;
};
int T;
void dfs(int i) {
  in[i] = T;
  T++;
  for (int j = 0; j < tr[i].size(); j++) {
    dfs(tr[i][j]);
  }
  out[i] = T - 1;
}
qu queries[200005];
int main() {
  n = 1;
  int q;
  scanf("%d %d", &v[0], &q);
  memset(ch, 0, sizeof(ch));
  for (int i = 0; i < q; i++) {
    int com;
    scanf("%d", &com);
    if (com == 1) {
      int u, val;
      scanf("%d %d", &u, &val);
      u--;
      queries[i].com = com;
      queries[i].u = u;
      tr[u].push_back(n++);
      v[n - 1] = val;
      par[n - 1] = u;
    } else {
      int u;
      scanf("%d", &u);
      u--;
      queries[i].com = com;
      queries[i].u = u;
    }
  }
  for (int i = 0; i < n; i++) ch[i] = 1;
  T = 0;
  dfs(0);
  mul(0, 0, n - 1, in[0], out[0], 1);
  add(0, 0, n - 1, in[0], v[0]);
  int n2 = 1;
  for (int i = 0; i < q; i++) {
    if (queries[i].com == 1) {
      int u = queries[i].u;
      mul(0, 0, n - 1, in[queries[i].u], out[queries[i].u], pw(ch[u], mod - 2));
      mul(0, 0, n - 1, in[queries[i].u], out[queries[i].u], ++ch[u]);
      add(0, 0, n - 1, in[n2], v[n2]);
      n2++;
    } else {
      long long res = get(0, 0, n - 1, in[queries[i].u], out[queries[i].u]).val;
      long long ml;
      if (queries[i].u > 0)
        ml = getMul(0, 0, n - 1, in[par[queries[i].u]]).lazy;
      else
        ml = 1;
      res *= pw(ml, mod - 2);
      res %= mod;
      int ans = res;
      printf("%d\n", ans);
    }
  }
}