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 n, m;
struct Que {
  int op, v, id;
} q[200010];
inline int Read() {
  char c = getchar();
  int num = 0;
  while ('0' > c || c > '9') c = getchar();
  while ('0' <= c && c <= '9') num = num * 10 + c - '0', c = getchar();
  return (num);
}
inline int Pow(int x, int y) {
  int rs = 1;
  while (y) {
    if (y & 1) rs = rs * 1ll * x % 1000000007;
    x = x * 1ll * x % 1000000007, y /= 2;
  }
  return (rs);
}
vector<int> e[200010];
int fa[200010], dfn[200010], tm, sz[200010], bl[200010], R[200010];
inline void Dfs(int x) {
  sz[x] = 1;
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa[x]) fa[e[x][i]] = x, Dfs(e[x][i]), sz[x] += sz[e[x][i]];
}
inline void Dfs2(int x, int y) {
  bl[x] = y, dfn[x] = ++tm;
  int k = 0;
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa[x] && sz[k] < sz[e[x][i]]) k = e[x][i];
  if (k) Dfs2(k, y);
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != fa[x] && e[x][i] != k) Dfs2(e[x][i], e[x][i]);
  R[x] = tm;
}
int t[200010 * 4];
inline void Add(int x, int l, int r, int a) {
  int md = (l + r) / 2;
  if (l == r) {
    t[x]++;
    return;
  }
  if (a <= md)
    Add(x * 2, l, md, a);
  else
    Add(x * 2 + 1, md + 1, r, a);
  t[x] = t[x * 2] * 1ll * t[x * 2 + 1] % 1000000007;
}
inline int Ask(int x, int l, int r, int a, int b) {
  int md = (l + r) / 2;
  if (l == a && r == b) return (t[x]);
  if (b <= md) return (Ask(x * 2, l, md, a, b));
  if (md < a) return (Ask(x * 2 + 1, md + 1, r, a, b));
  int L = Ask(x * 2, l, md, a, md);
  int R = Ask(x * 2 + 1, md + 1, r, md + 1, b);
  return (L * 1ll * R % 1000000007);
}
inline int Solv(int x) {
  int rs = 1;
  while (x) {
    int nm = Ask(1, 1, n, dfn[bl[x]], dfn[x]);
    rs = rs * 1ll * nm % 1000000007, x = fa[bl[x]];
  }
  return (rs);
}
int ts[200010 * 4], lzy[200010 * 4];
inline void Down(int x) {
  if (!lzy[x]) return;
  int l = x * 2, r = x * 2 + 1;
  ts[l] = ts[l] * 1ll * lzy[x] % 1000000007;
  lzy[l] = lzy[l] * 1ll * lzy[x] % 1000000007;
  ts[r] = ts[r] * 1ll * lzy[x] % 1000000007;
  lzy[r] = lzy[r] * 1ll * lzy[x] % 1000000007;
  lzy[x] = 1;
}
inline void Addp(int x, int l, int r, int a, int b, int c) {
  if (l == a && r == b) {
    ts[x] = ts[x] * 1ll * c % 1000000007;
    lzy[x] = lzy[x] * 1ll * c % 1000000007;
    return;
  }
  int md = (l + r) / 2;
  Down(x);
  if (b <= md) Addp(x * 2, l, md, a, b, c);
  if (md < a) Addp(x * 2 + 1, md + 1, r, a, b, c);
  if (a <= md && md < b) {
    Addp(x * 2, l, md, a, md, c);
    Addp(x * 2 + 1, md + 1, r, md + 1, b, c);
  }
  ts[x] = (ts[x * 2] + ts[x * 2 + 1]) % 1000000007;
}
inline void Adds(int x, int l, int r, int a, int b) {
  ts[x] = (ts[x] + b) % 1000000007;
  if (l == r) return;
  int md = (l + r) / 2;
  Down(x);
  if (a <= md)
    Adds(x * 2, l, md, a, b);
  else
    Adds(x * 2 + 1, md + 1, r, a, b);
  ts[x] = (ts[x * 2] + ts[x * 2 + 1]) % 1000000007;
}
inline int Asks(int x, int l, int r, int a, int b) {
  int md = (l + r) / 2;
  if (l == a && r == b) return (ts[x]);
  Down(x);
  if (b <= md) return (Asks(x * 2, l, md, a, b));
  if (md < a) return (Asks(x * 2 + 1, md + 1, r, a, b));
  int L = Asks(x * 2, l, md, a, md);
  int R = Asks(x * 2 + 1, md + 1, r, md + 1, b);
  return ((L + R) % 1000000007);
}
int du[200010];
int main() {
  int v1 = Read();
  n = 1, m = Read();
  for (int i = 1; i <= m; i++) {
    q[i].op = Read(), q[i].v = Read();
    if (q[i].op == 1) {
      e[q[i].v].push_back(++n);
      q[i].id = n, q[i].v = Read();
    }
  }
  Dfs(1);
  Dfs2(1, 1);
  Add(1, 1, n, dfn[1]);
  Adds(1, 1, n, dfn[1], v1);
  du[1] = 1;
  for (int i = 1; i <= n * 4; i++) lzy[i] = 1;
  for (int i = 1; i <= m; i++) {
    if (q[i].op == 1) {
      int x = q[i].id;
      int d = Solv(fa[x]);
      du[x]++, du[fa[x]]++;
      Adds(1, 1, n, dfn[x], d * 1ll * q[i].v % 1000000007);
      d = du[fa[x]] * 1ll * Pow(du[fa[x]] - 1, 1000000007 - 2) % 1000000007;
      Addp(1, 1, n, dfn[fa[x]], R[fa[x]], d);
      Add(1, 1, n, dfn[x]);
      Add(1, 1, n, dfn[fa[x]]);
    } else {
      int x = q[i].v;
      int ans = Asks(1, 1, n, dfn[x], R[x]);
      int d = Solv(fa[x]);
      d = Pow(d, 1000000007 - 2);
      printf("%d\n", ans * 1ll * d % 1000000007);
    }
  }
}