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 long long MOD = 1e9 + 7;
const int MN = 400111;
int getIn[MN], getOut[MN], n, dfsNum;
vector<int> ke[MN];
int a[MN];
struct Query {
  int u, v;
  int typ;
  void read() {
    scanf("%d", &typ);
    if (typ == 1) {
      ++n;
      scanf("%d", &u);
      v = n;
      scanf("%d", &a[v]);
      ke[u].push_back(v);
    } else {
      scanf("%d", &u);
    }
  }
} queries[MN];
void dfs(int u) {
  getIn[u] = ++dfsNum;
  for (int v : ke[u]) {
    dfs(v);
  }
  getOut[u] = ++dfsNum;
}
long long power(long long x, long long k) {
  long long res = 1;
  while (k > 0) {
    if (k & 1) res = res * x % MOD;
    x = x * x % MOD;
    k >>= 1;
  }
  return res;
}
long long inverse(long long x) { return power(x, MOD - 2); }
struct Node {
  long long mult;
  long long sum;
  long long lazy;
} it[MN * 4];
void updateMult(int i, int l, int r, int u, long long delta) {
  if (u < l || r < u) return;
  if (l == r) {
    it[i].mult = it[i].mult * delta % MOD;
    return;
  }
  int mid = (l + r) >> 1;
  updateMult(i << 1, l, mid, u, delta);
  updateMult(i << 1 | 1, mid + 1, r, u, delta);
  it[i].mult = it[i << 1].mult * it[i << 1 | 1].mult % MOD;
}
long long getMult(int i, int l, int r, int u, int v) {
  if (v < l || r < u) return 1ll;
  if (u <= l && r <= v) {
    return it[i].mult;
  }
  int mid = (l + r) >> 1;
  return getMult(i << 1, l, mid, u, v) * getMult(i << 1 | 1, mid + 1, r, u, v) %
         MOD;
}
void up(int i) { it[i].sum = (it[i << 1].sum + it[i << 1 | 1].sum) % MOD; }
void down(int i) {
  if (it[i].lazy > 1) {
    long long t = it[i].lazy;
    it[i].lazy = 1;
    it[i << 1].lazy = it[i << 1].lazy * t % MOD;
    it[i << 1].sum = it[i << 1].sum * t % MOD;
    it[i << 1 | 1].lazy = it[i << 1 | 1].lazy * t % MOD;
    it[i << 1 | 1].sum = it[i << 1 | 1].sum * t % MOD;
  }
}
void multiply(int i, int l, int r, int u, int v, long long val) {
  if (v < l || r < u) return;
  if (u <= l && r <= v) {
    it[i].lazy = (it[i].lazy * val) % MOD;
    it[i].sum = (it[i].sum * val) % MOD;
    return;
  }
  down(i);
  int mid = (l + r) >> 1;
  multiply(i << 1, l, mid, u, v, val);
  multiply(i << 1 | 1, mid + 1, r, u, v, val);
  up(i);
}
void update(int i, int l, int r, int u, long long val) {
  if (u < l || r < u) return;
  if (l == r) {
    it[i].sum = (it[i].sum + val) % MOD;
    return;
  }
  down(i);
  int mid = (l + r) >> 1;
  update(i << 1, l, mid, u, val);
  update(i << 1 | 1, mid + 1, r, u, val);
  up(i);
}
long long get(int i, int l, int r, int u, int v) {
  if (v < l || r < u) return 0;
  if (u <= l && r <= v) return it[i].sum;
  down(i);
  int mid = (l + r) >> 1;
  long long res =
      (get(i << 1, l, mid, u, v) + get(i << 1 | 1, mid + 1, r, u, v)) % MOD;
  up(i);
  return res;
}
int sz[MN];
void build(int i, int l, int r) {
  it[i].sum = 0;
  it[i].mult = 1;
  it[i].lazy = 1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  int q;
  while (scanf("%d%d", &a[1], &q) == 2) {
    for (int i = (1), _b = (q); i <= _b; ++i) ke[i].clear();
    n = 1;
    for (int i = (1), _b = (q); i <= _b; ++i) {
      queries[i].read();
    }
    dfsNum = 0;
    dfs(1);
    n *= 2;
    build(1, 1, n);
    sz[1] = 1;
    update(1, 1, n, getIn[1], a[1]);
    for (int i = (1), _b = (q); i <= _b; ++i) {
      if (queries[i].typ == 1) {
        int u = queries[i].u;
        int v = queries[i].v;
        long long mult1 = getMult(1, 1, n, 1, getIn[u]);
        sz[v] = 1;
        updateMult(1, 1, n, getIn[u], inverse(sz[u]) * (sz[u] + 1) % MOD);
        updateMult(1, 1, n, getOut[u], sz[u] * inverse(sz[u] + 1) % MOD);
        sz[u] += 1;
        long long mult = getMult(1, 1, n, 1, getIn[v]);
        long long mult2 = getMult(1, 1, n, 1, getIn[u]);
        multiply(1, 1, n, getIn[u], getOut[u], inverse(mult1) * mult2 % MOD);
        update(1, 1, n, getIn[v], (mult * a[v]) % MOD);
      } else {
        int u = queries[i].u;
        long long sum = get(1, 1, n, getIn[u], getOut[u]);
        long long mult = getMult(1, 1, n, 1, getIn[u] - 1);
        sum = sum * inverse(mult) % MOD;
        printf("%d\n", (int)sum);
      }
    }
  }
}