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 = 2e5 + 10;
const long long MOD = 1000000007;
long long exp(long long x, long long p) {
  if (p == 0) return 1;
  long long ans = exp(x, p / 2);
  ans = (ans * ans) % MOD;
  if (p % 2) {
    (ans *= x) %= MOD;
  }
  return ans % MOD;
}
vector<int> grafo[MAXN];
vector<pair<pair<int, int>, pair<long long, int> > > ops;
int tin[MAXN], tout[MAXN], T, filhos[MAXN], pai[MAXN], v[MAXN];
void dfs(int x, int p) {
  tin[x] = ++T;
  for (int v : grafo[x]) {
    if (v == p) continue;
    dfs(v, x);
  }
  tout[x] = T;
}
struct nodeseg {
  long long sumc, m, lz;
  bool haslz, flag;
  nodeseg(long long _sc = 0, long long _m = 0, long long _lz = 1, bool _h = 0,
          bool _f = 0) {
    sumc = _sc;
    m = _m;
    lz = _lz;
    haslz = _h;
    flag = _f;
  }
} seg[4 * MAXN];
void unlazy(int node, int x, int y) {
  if (seg[node].haslz) {
    seg[node].m *= seg[node].lz % MOD;
    seg[node].m %= MOD;
    seg[node].sumc %= MOD;
    seg[node].lz %= MOD;
    seg[node].sumc *= seg[node].lz;
    seg[node].sumc %= MOD;
    if (x != y) {
      seg[node << 1].haslz = 1, (seg[node << 1].lz *= seg[node].lz) %= MOD;
      seg[(node << 1) | 1].haslz = 1,
                        (seg[(node << 1) | 1].lz *= seg[node].lz) %= MOD;
    }
    seg[node].haslz = 0;
    seg[node].lz = 1;
  }
}
void update1(int node, int x, int y, int id, long long v, long long m) {
  unlazy(node, x, y);
  if (x > id || y < id) return;
  if (x == y) {
    seg[node].sumc = v * m;
    seg[node].sumc %= MOD;
    seg[node].m = m;
    return;
  }
  update1(node << 1, x, ((x + y) >> 1) + 0, id, v, m);
  update1((node << 1) | 1, ((x + y) >> 1) + 1, y, id, v, m);
  seg[node].sumc = seg[node << 1].sumc + seg[(node << 1) | 1].sumc;
  seg[node].sumc %= MOD;
}
void update2(int node, int x, int y, int l, int r, long long m) {
  unlazy(node, x, y);
  if (x > r || y < l) return;
  if (x >= l && y <= r) {
    seg[node].lz *= m;
    seg[node].haslz = 1;
    unlazy(node, x, y);
    return;
  }
  update2(node << 1, x, ((x + y) >> 1) + 0, l, r, m);
  update2((node << 1) | 1, ((x + y) >> 1) + 1, y, l, r, m);
  seg[node].sumc = seg[node << 1].sumc + seg[(node << 1) | 1].sumc;
  seg[node].sumc %= MOD;
}
long long queryc(int node, int x, int y, int l, int r) {
  unlazy(node, x, y);
  if (x > r || y < l) return 0;
  if (x >= l && y <= r) return seg[node].sumc;
  long long e = queryc(node << 1, x, ((x + y) >> 1) + 0, l, r);
  long long d = queryc((node << 1) | 1, ((x + y) >> 1) + 1, y, l, r);
  return (e + d) % MOD;
}
long long queryd(int node, int x, int y, int id) {
  unlazy(node, x, y);
  if (x > id || y < id) return 0;
  if (x == y) return seg[node].m;
  long long e = queryd(node << 1, x, ((x + y) >> 1) + 0, id);
  long long d = queryd((node << 1) | 1, ((x + y) >> 1) + 1, y, id);
  return e + d;
}
int q, n = 1;
long long v1;
int main() {
  scanf("%lld %d", &v1, &q);
  v[1] = v1;
  int qaux = q;
  while (qaux--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int p;
      long long vv;
      scanf("%d %lld", &p, &vv);
      grafo[p].push_back(++n);
      grafo[n].push_back(p);
      pai[n] = p;
      v[n] = vv;
      ops.push_back({{p, n}, {vv, t}});
    } else {
      int x;
      scanf("%d", &x);
      ops.push_back({{x, 0}, {0, t}});
    }
  }
  dfs(1, 1);
  update1(1, 1, n, tin[1], v1, 1);
  for (int i = 0; i < q; i++) {
    int t = ops[i].second.second;
    if (t == 1) {
      int p = ops[i].first.first;
      int va = ops[i].first.second;
      long long vv = ops[i].second.first;
      long long m = queryd(1, 1, n, tin[p]);
      update1(1, 1, n, tin[va], vv, m);
      update2(1, 1, n, tin[p], tout[p],
              (filhos[p] + 2) * exp(filhos[p] + 1, MOD - 2));
      filhos[p]++;
    } else {
      int x = ops[i].first.first;
      long long ans = queryc(1, 1, n, tin[x], tout[x]) % MOD;
      ans = (ans * (filhos[x] + 1)) % MOD;
      long long aux = exp(queryd(1, 1, n, tin[x]) % MOD, MOD - 2) % MOD;
      ans = (ans * aux) % MOD;
      printf("%lld\n", ans);
    }
  }
}