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;
template <typename T>
inline bool upmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 62;
const int mods = 1e9 + 7;
const int MAXN = 400005;
const int INF = 0x3f3f3f3f;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
pair<int, int> Q[MAXN];
vector<int> e[MAXN];
int n, DFN = 0, dfn[MAXN], fns[MAXN], sz[MAXN], fa[MAXN], c[MAXN];
int upd(int x, int y) { return x + y >= mods ? x + y - mods : x + y; }
int quick_pow(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = 1ll * ret * x % mods;
    x = 1ll * x * x % mods;
  }
  return ret;
}
int Inv(int x) { return quick_pow(x, mods - 2); }
void dfs(int x) {
  dfn[x] = ++DFN;
  for (auto v : e[x]) dfs(v);
  fns[x] = DFN;
}
int s[MAXN << 2], tag[MAXN << 2];
void build(int x, int l, int r) {
  tag[x] = 1, s[x] = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
}
void down(int x) {
  if (tag[x] == 1) return;
  tag[x << 1] = 1ll * tag[x << 1] * tag[x] % mods;
  tag[x << 1 | 1] = 1ll * tag[x << 1 | 1] * tag[x] % mods;
  s[x << 1] = 1ll * s[x << 1] * tag[x] % mods;
  s[x << 1 | 1] = 1ll * s[x << 1 | 1] * tag[x] % mods;
  tag[x] = 1;
}
int query(int x, int l, int r, int L, int R) {
  if (l >= L && r <= R) return s[x];
  down(x);
  int mid = (l + r) >> 1;
  if (R <= mid)
    return query(x << 1, l, mid, L, R);
  else if (L > mid)
    return query(x << 1 | 1, mid + 1, r, L, R);
  else
    return upd(query(x << 1, l, mid, L, mid),
               query(x << 1 | 1, mid + 1, r, mid + 1, R));
}
void update(int x, int l, int r, int L, int R, int y) {
  if (l >= L && r <= R) {
    s[x] = 1ll * s[x] * y % mods, tag[x] = 1ll * tag[x] * y % mods;
    return;
  }
  down(x);
  int mid = (l + r) >> 1;
  if (R <= mid)
    update(x << 1, l, mid, L, R, y);
  else if (L > mid)
    update(x << 1 | 1, mid + 1, r, L, R, y);
  else
    update(x << 1, l, mid, L, mid, y),
        update(x << 1 | 1, mid + 1, r, mid + 1, R, y);
  s[x] = upd(s[x << 1], s[x << 1 | 1]);
}
void change(int x, int l, int r, int y, int z) {
  if (l == r) {
    s[x] = upd(s[x], z);
    return;
  }
  down(x);
  int mid = (l + r) >> 1;
  if (y <= mid)
    change(x << 1, l, mid, y, z);
  else
    change(x << 1 | 1, mid + 1, r, y, z);
  s[x] = upd(s[x << 1], s[x << 1 | 1]);
}
signed main() {
  c[1] = read(), n = 1;
  int m = read();
  for (int i = 1; i <= m; i++) {
    int opt = read();
    if (opt == 1)
      fa[++n] = read(), e[fa[n]].push_back(n), c[n] = read(),
      Q[i] = make_pair(1, n);
    else
      Q[i] = make_pair(2, read());
  }
  dfs(1);
  build(1, 1, n);
  change(1, 1, n, dfn[1], c[1]);
  for (int i = 1; i <= n; i++) sz[i] = 1;
  for (int i = 1; i <= m; i++) {
    int v = Q[i].second, Fa = fa[v];
    if (Q[i].first == 1) {
      int t = query(1, 1, n, dfn[Fa], dfn[Fa]);
      int p = 1ll * t * c[v] % mods * Inv(c[Fa]) % mods;
      change(1, 1, n, dfn[v], p);
      update(1, 1, n, dfn[Fa], fns[Fa],
             1ll * (sz[Fa] + 1) * Inv(sz[Fa]) % mods);
      sz[Fa]++;
    } else {
      int t = query(1, 1, n, dfn[v], fns[v]);
      if (v != 1)
        t = 1ll * t * Inv(query(1, 1, n, dfn[Fa], dfn[Fa])) % mods * c[Fa] %
            mods;
      printf("%d\n", t);
    }
  }
  return 0;
}