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 double eps = 1e-12;
const int MODULO = 1000000007;
const int N = 200007;
vector<int> edge[N];
long long cover[N * 8];
long long prodSum[N * 8], prod[N * 8];
long long at[N];
int inTime[N], outTime[N];
int timeStamp = 0;
int value[N];
void dfs(int x, int fa) {
  inTime[x] = timeStamp++;
  for (__typeof(edge[x].begin()) it = edge[x].begin(); it != edge[x].end();
       it++) {
    if (*it == fa) {
      continue;
    }
    dfs(*it, x);
  }
  outTime[x] = timeStamp - 1;
}
void build(int left, int right, int x) {
  cover[x] = 1;
  prodSum[x] = prod[x] = 0;
  if (left < right) {
    int mid = (left + right) >> 1;
    build(left, mid, x * 2);
    build(mid + 1, right, x * 2 + 1);
  }
}
inline void mult(int x, long long delta) {
  cover[x] = cover[x] * delta % MODULO;
  prod[x] = prod[x] * delta % MODULO;
  prodSum[x] = prodSum[x] * delta % MODULO;
}
inline void pushDown(int x) {
  if (cover[x] != 1) {
    mult(x * 2, cover[x]);
    mult(x * 2 + 1, cover[x]);
    cover[x] = 1;
  }
}
inline void pushUp(int x) {
  prod[x] = (prod[x * 2] + prod[x * 2 + 1]);
  if (prod[x] >= MODULO) prod[x] -= MODULO;
  prodSum[x] = (prodSum[x * 2] + prodSum[x * 2 + 1]);
  if (prodSum[x] >= MODULO) prodSum[x] -= MODULO;
}
void change(int left, int right, int l, int r, int x, long long delta) {
  if (l <= left && r >= right) {
    mult(x, delta);
    return;
  }
  pushDown(x);
  int mid = (left + right) >> 1;
  if (l <= mid) change(left, mid, l, r, x * 2, delta);
  if (r > mid) change(mid + 1, right, l, r, x * 2 + 1, delta);
  pushUp(x);
}
void changeAt(int left, int right, int at, int x, long long val,
              long long key = 1) {
  if (left == right) {
    prod[x] = key;
    prodSum[x] = val * key % MODULO;
    return;
  }
  pushDown(x);
  int mid = (left + right) >> 1;
  if (at <= mid) {
    changeAt(left, mid, at, x * 2, val, key);
  } else {
    changeAt(mid + 1, right, at, x * 2 + 1, val, key);
  }
  pushUp(x);
}
long long getProd(int left, int right, int l, int r, int x) {
  if (l <= left && r >= right) {
    return prod[x];
  }
  pushDown(x);
  int mid = (left + right) >> 1;
  long long res = 0;
  if (l <= mid) res += getProd(left, mid, l, r, x * 2);
  if (r > mid) res += getProd(mid + 1, right, l, r, x * 2 + 1);
  if (res >= MODULO) res -= MODULO;
  return res;
}
long long getProdSum(int left, int right, int l, int r, int x) {
  if (l <= left && r >= right) {
    return prodSum[x];
  }
  pushDown(x);
  int mid = (left + right) >> 1;
  long long res = 0;
  if (l <= mid) res += getProdSum(left, mid, l, r, x * 2);
  if (r > mid) res += getProdSum(mid + 1, right, l, r, x * 2 + 1);
  if (res >= MODULO) res -= MODULO;
  return res;
}
long long powMod(long long x, int y) {
  long long z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = z * x % MODULO;
    x = x * x % MODULO;
  }
  return z;
}
long long inv(long long x) { return powMod(x, MODULO - 2); }
int degree[N], parent[N];
int p0[N], p1[N], p2[N], lab[N];
int main() {
  int q;
  cin >> value[0] >> q;
  parent[0] = -1;
  int n = 1;
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &p0[i], &p1[i]);
    if (p0[i] == 1) {
      scanf("%d", &p2[i]);
    }
    int type = p0[i];
    if (type == 1) {
      int pi = p1[i] - 1;
      int vi = p2[i];
      edge[pi].push_back(n);
      parent[n] = pi;
      lab[i] = n;
      value[n++] = vi;
    } else {
    }
  }
  dfs(0, -1);
  build(0, n - 1, 1);
  changeAt(0, n - 1, inTime[0], 1, value[0]);
  for (int i = 0; i < q; i++) {
    int type = p0[i];
    if (type == 1) {
      int node = lab[i];
      int pi = parent[node];
      int vi = value[node];
      ++degree[pi];
      change(0, n - 1, inTime[pi], outTime[pi], 1,
             inv(degree[pi]) * (degree[pi] + 1) % MODULO);
      long long key = getProd(0, n - 1, inTime[pi], inTime[pi], 1);
      changeAt(0, n - 1, inTime[node], 1, vi, key);
    } else {
      int ui = p1[i] - 1;
      long long coef = 1;
      if (parent[ui] != -1) {
        int p = parent[ui];
        coef = inv(getProd(0, n - 1, inTime[p], inTime[p], 1));
      }
      long long result = getProdSum(0, n - 1, inTime[ui], outTime[ui], 1);
      result = result * coef % MODULO;
      result = (result + MODULO) % MODULO;
      cout << result << endl;
    }
  }
  return 0;
}