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;
int tym;
long long modulo(long long a, long long b, long long c) {
  long long x = 1LL, y = a;
  while (b > 0LL) {
    if (b % 2LL == 1LL) {
      x = (x * y) % c;
    }
    y = (y * y) % c;
    b /= 2LL;
  }
  return x % c;
}
struct node {
  int t, x;
  long long v;
} q[412345];
long long child[412345], val[412345];
int st[412345], en[412345], par[412345];
vector<int> adj[412345];
long long mul[6 * 412345], ans[6 * 412345], flag[6 * 412345];
void p_update(int n, int b, int e, int x, long long v) {
  if (flag[n] != 1) {
    mul[n] = ((mul[n] * flag[n]) % 1000000007LL);
    ans[n] = ((ans[n] * flag[n]) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * flag[n]) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * flag[n]) % 1000000007LL;
    }
    flag[n] = 1LL;
  }
  if (b > x || e < x) return;
  if (b == e && e == x) {
    ans[n] = (v * mul[n]) % 1000000007LL;
    return;
  }
  int l = n << 1, mid = (b + e) >> 1;
  p_update(l, b, mid, x, v);
  p_update(l + 1, mid + 1, e, x, v);
  mul[n] = (mul[l] + mul[l + 1]);
  ans[n] = (ans[l] + ans[l + 1]);
  if (ans[n] >= 1000000007LL) ans[n] -= 1000000007LL;
  if (mul[n] >= 1000000007LL) mul[n] -= 1000000007LL;
}
void r_update(int n, int b, int e, int x, int y, long long v) {
  if (flag[n] != 1) {
    mul[n] = ((mul[n] * flag[n]) % 1000000007LL);
    ans[n] = ((ans[n] * flag[n]) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * flag[n]) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * flag[n]) % 1000000007LL;
    }
    flag[n] = 1LL;
  }
  if (b > y || e < x) return;
  if (b >= x && e <= y) {
    mul[n] = ((mul[n] * v) % 1000000007LL);
    ans[n] = ((ans[n] * v) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * v) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * v) % 1000000007LL;
    }
    return;
  }
  int l = n << 1, mid = (b + e) >> 1;
  r_update(l, b, mid, x, y, v);
  r_update(l + 1, mid + 1, e, x, y, v);
  mul[n] = (mul[l] + mul[l + 1]);
  ans[n] = (ans[l] + ans[l + 1]);
  if (ans[n] >= 1000000007LL) ans[n] -= 1000000007LL;
  if (mul[n] >= 1000000007LL) mul[n] -= 1000000007LL;
}
long long r_query(int n, int b, int e, int x, int y) {
  if (flag[n] != 1) {
    mul[n] = ((mul[n] * flag[n]) % 1000000007LL);
    ans[n] = ((ans[n] * flag[n]) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * flag[n]) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * flag[n]) % 1000000007LL;
    }
    flag[n] = 1LL;
  }
  if (b > y || e < x) return 0LL;
  if (b >= x && e <= y) {
    return ans[n];
  }
  int l = n << 1, mid = (b + e) >> 1;
  long long an = r_query(l, b, mid, x, y) + r_query(l + 1, mid + 1, e, x, y);
  if (an >= 1000000007LL) an -= 1000000007LL;
  return an;
}
long long p_query(int n, int b, int e, int x) {
  if (flag[n] != 1) {
    mul[n] = ((mul[n] * flag[n]) % 1000000007LL);
    ans[n] = ((ans[n] * flag[n]) % 1000000007LL);
    if (b != e) {
      flag[2 * n] = (flag[2 * n] * flag[n]) % 1000000007LL;
      flag[2 * n + 1] = (flag[2 * n + 1] * flag[n]) % 1000000007LL;
    }
    flag[n] = 1LL;
  }
  if (b > x || e < x) return 0LL;
  if (b == e && e == x) {
    return mul[n];
  }
  int l = n << 1, mid = (b + e) >> 1;
  long long an = p_query(l, b, mid, x) + p_query(l + 1, mid + 1, e, x);
  if (an >= 1000000007LL) an -= 1000000007LL;
  return an;
}
void build(int n, int b, int e) {
  flag[n] = 1LL;
  if (b == e) {
    mul[n] = 1LL;
    return;
  }
  int l = n << 1, mid = (b + e) >> 1;
  build(l, b, mid);
  build(l + 1, mid + 1, e);
  mul[n] = (mul[l] + mul[l + 1]);
  if (mul[n] >= 1000000007LL) mul[n] -= 1000000007LL;
}
void dfs(int u, int p) {
  st[u] = tym;
  par[u] = p;
  tym++;
  for (int i = 0; i < adj[u].size(); i++) dfs(adj[u][i], u);
  en[u] = tym - 1;
}
int main() {
  int i, j, n, qu;
  long long p;
  scanf("%lld %d", &p, &qu);
  val[1] = p;
  n = 2;
  for (i = 0; i < qu; i++) {
    scanf("%d", &q[i].t);
    if (q[i].t == 1) {
      int p;
      scanf("%d %lld", &p, &q[i].v);
      adj[p].push_back(n);
      q[i].x = n;
      val[n] = q[i].v;
      n++;
    } else
      scanf("%d", &q[i].x), q[i].v = 0LL;
  }
  tym = 0;
  n--;
  dfs(1, 0);
  build(1, 0, n - 1);
  child[1] = 1;
  p_update(1, 0, n - 1, st[1], val[1]);
  for (int i = 0; i < qu; i++) {
    if (q[i].t == 1) {
      int x = par[q[i].x];
      long long v =
          (modulo(child[x], 1000000007LL - 2, 1000000007LL) * (child[x] + 1)) %
          1000000007LL;
      r_update(1, 0, n - 1, st[x], en[x], v);
      child[x]++;
      child[q[i].x] = 1;
      p_update(1, 0, n - 1, st[q[i].x], q[i].v);
    } else {
      long long p, an = r_query(1, 0, n - 1, st[q[i].x], en[q[i].x]);
      if (q[i].x != 1)
        p = p_query(1, 0, n - 1, st[par[q[i].x]]);
      else
        p = 1;
      an = (an * modulo(p, 1000000007LL - 2, 1000000007LL)) % 1000000007LL;
      printf("%lld\n", an);
    }
  }
  return 0;
}