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 int mod = 1000000007;
int get_inv(int x) {
  return (x == 1) ? 1 : (mod - (long long)(mod / x) * get_inv(mod % x) % mod);
}
const int MaxN = 200010, MaxT = 1 << 19;
struct tree_node {
  int k, sum;
  int lazy;
} T[MaxT];
int v[MaxN], deg[MaxN];
class Graph {
 public:
  int en[MaxN], next[MaxN], point[MaxN], tot;
  void add_edge(int x, int y) {
    next[++tot] = en[x];
    en[x] = tot;
    point[tot] = y;
  }
} G;
int in[MaxN], out[MaxN];
int n, q;
int dfn;
void dfs(int now) {
  in[now] = ++dfn;
  for (int i = G.en[now]; i; i = G.next[i]) dfs(G.point[i]);
  out[now] = dfn;
}
void build_tree(int l, int r, int now) {
  for (int i = 1; i < MaxT; ++i) T[i].k = T[i].lazy = 1;
}
inline int mul(int &x, int v) { return (x = (long long)x * v % mod); }
inline int inc(int x, int v) {
  x += v;
  return x >= mod ? x - mod : x;
}
void add_lazy(int now, int lazy) {
  mul(T[now].lazy, lazy);
  mul(T[now].k, lazy);
  mul(T[now].sum, lazy);
}
void push_down(int now) {
  if (T[now].lazy != 1) {
    add_lazy(now << 1, T[now].lazy);
    add_lazy(now << 1 | 1, T[now].lazy);
    T[now].lazy = 1;
  }
}
void update(int now) { T[now].sum = inc(T[now << 1].sum, T[now << 1 | 1].sum); }
void modify_v(int l, int r, int x, int v, int now) {
  if (l == r) {
    T[now].sum = 1ll * T[now].k * v % mod;
    return;
  }
  int mid = (l + r) >> 1;
  push_down(now);
  if (x <= mid)
    modify_v(l, mid, x, v, now << 1);
  else
    modify_v(mid + 1, r, x, v, now << 1 | 1);
  update(now);
}
void modify_k(int l, int r, int x, int y, int k, int now) {
  if ((r < x) || (y < l)) return;
  if ((x <= l) && (r <= y)) return add_lazy(now, k);
  int mid = (l + r) >> 1;
  push_down(now);
  modify_k(l, mid, x, y, k, now << 1);
  modify_k(mid + 1, r, x, y, k, now << 1 | 1);
  update(now);
}
int query_k(int l, int r, int x, int now) {
  if (l == r) return T[now].k;
  int mid = (l + r) >> 1;
  push_down(now);
  if (x <= mid)
    return query_k(l, mid, x, now << 1);
  else
    return query_k(mid + 1, r, x, now << 1 | 1);
}
int query_sum(int l, int r, int x, int y, int now) {
  if ((r < x) || (y < l)) return 0;
  if ((x <= l) && (r <= y)) return T[now].sum;
  int mid = (l + r) >> 1;
  push_down(now);
  return inc(query_sum(l, mid, x, y, now << 1),
             query_sum(mid + 1, r, x, y, now << 1 | 1));
}
void debug() {
  for (int i = 1; i <= 17; ++i)
    printf("%d: %d %d %d\n", i, T[i].sum, T[i].k, T[i].lazy);
}
int main() {
  static int type[MaxN], f[MaxN], u[MaxN];
  scanf("%d%d", v + 1, &q);
  n = 1;
  for (int i = 1; i <= q; ++i) {
    scanf("%d", type + i);
    if (type[i] == 1) {
      u[i] = ++n;
      scanf("%d%d", &f[n], &v[n]);
      G.add_edge(f[n], n);
    } else
      scanf("%d", u + i);
  }
  dfs(1);
  build_tree(1, n, 1);
  modify_v(1, n, in[1], v[1], 1);
  deg[1] = 1;
  for (int i = 1; i <= q; ++i)
    if (type[i] == 2) {
      int ans = query_sum(1, n, in[u[i]], out[u[i]], 1), k;
      if (u[i] == 1)
        k = 1;
      else
        k = query_k(1, n, in[f[u[i]]], 1);
      ans = (long long)ans * get_inv(k) % mod;
      printf("%d\n", ans);
    } else {
      int k = (long long)(deg[f[u[i]]] + 1) * get_inv(deg[f[u[i]]]) % mod;
      ++deg[f[u[i]]];
      modify_k(1, n, in[f[u[i]]], out[f[u[i]]], k, 1);
      deg[u[i]] = 1;
      modify_v(1, n, in[u[i]], v[u[i]], 1);
    }
  return 0;
}