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, typename L>
bool smax(T &x, L y) {
  return x < y ? (x = y, true) : false;
}
template <typename T, typename L>
bool smin(T &x, L y) {
  return y < x ? (x = y, true) : false;
}
struct Query {
  int t, p, v, u;
};
struct node {
  long long sm, lz;
  node() { sm = 0, lz = 1; }
};
void dfs(int);
void update(int, int, int, int, int);
void update(int, int, int, int, int, int);
int get(int, int, int, int);
void shift(int);
int query(int, int, int, int, int);
int mul(int, int);
int inv(int, int);
int pw(int, int);
int add(int, int);
const int MAXN = 2e5 + 15;
vector<int> val;
Query a[MAXN];
node tree[MAXN << 2];
int st[MAXN], ft[MAXN], ver[MAXN];
vector<int> adj[MAXN];
int d[MAXN], par[MAXN];
int n = 2, q, tme = 2;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cerr << "HELLO WORLD :)\n";
  val.resize(2);
  cin >> val[1] >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i].t;
    if (a[i].t == 1) {
      cin >> a[i].p >> a[i].v;
      val.push_back(a[i].v);
      par[n] = a[i].p;
      adj[a[i].p].push_back(n++);
    } else
      cin >> a[i].u;
  }
  dfs(1);
  update(1, 1, n, st[1], val[1]);
  for (int i = 0; i < q; i++) {
    if (a[i].t == 1) {
      int t = inv(d[a[i].p] + 2, d[a[i].p] + 1);
      update(1, 1, n, st[a[i].p], ft[a[i].p], t);
      int x = get(1, 1, n, st[a[i].p]);
      x = inv(x, val[a[i].p]);
      update(1, 1, n, st[tme++], mul(a[i].v, x));
      d[a[i].p]++;
    } else {
      int mem = query(1, 1, n, st[a[i].u], ft[a[i].u]);
      int rel = 1;
      if (a[i].u != 1) {
        rel = get(1, 1, n, st[par[a[i].u]]);
        rel = inv(rel, val[par[a[i].u]]);
      }
      mem = inv(mem, rel);
      cout << mem << '\n';
    }
  }
}
void dfs(int v) {
  static int t = 1;
  st[v] = t++;
  ver[st[v]] = v;
  for (auto u : adj[v]) dfs(u);
  ft[v] = t;
}
int pw(int p, int v) {
  int ret = 1;
  for (; v; v >>= 1, p = 1ll * p * p % 1000000007ll)
    if (v & 1) ret = 1ll * ret * p % 1000000007ll;
  return ret;
}
int mul(int a, int b) { return 1ll * a * b % 1000000007ll; }
int inv(int a, int b) { return mul(a, pw(b, 1000000007ll - 2)); }
int add(int a, int b) { return (a + b) % 1000000007ll; }
void shift(int id) {
  tree[id << 1].sm = mul(tree[id << 1].sm, tree[id].lz);
  tree[id << 1].lz = mul(tree[id << 1].lz, tree[id].lz);
  tree[id << 1 | 1].sm = mul(tree[id << 1 | 1].sm, tree[id].lz);
  tree[id << 1 | 1].lz = mul(tree[id << 1 | 1].lz, tree[id].lz);
  tree[id].lz = 1;
}
int query(int id, int b, int e, int l, int r) {
  if (b >= r || e <= l) return 0;
  if (b >= l && e <= r) return tree[id].sm;
  shift(id);
  int mid = (b + e) >> 1;
  return add(query(id << 1, b, mid, l, r), query(id << 1 | 1, mid, e, l, r));
}
int get(int id, int b, int e, int p) {
  if (b == e - 1) return tree[id].sm;
  shift(id);
  int mid = (b + e) >> 1;
  if (p < mid) return get(id << 1, b, mid, p);
  return get(id << 1 | 1, mid, e, p);
}
void update(int id, int b, int e, int l, int r, int val) {
  if (b >= r || e <= l) return;
  if (b >= l && e <= r) {
    tree[id].sm = mul(tree[id].sm, val);
    tree[id].lz = mul(tree[id].lz, val);
    return;
  }
  shift(id);
  int mid = (b + e) >> 1;
  update(id << 1, b, mid, l, r, val);
  update(id << 1 | 1, mid, e, l, r, val);
  tree[id].sm = add(tree[id << 1].sm, tree[id << 1 | 1].sm);
}
void update(int id, int b, int e, int p, int val) {
  if (b == e - 1) {
    tree[id].sm = val;
    return;
  }
  shift(id);
  int mid = (b + e) >> 1;
  if (p < mid)
    update(id << 1, b, mid, p, val);
  else
    update(id << 1 | 1, mid, e, p, val);
  tree[id].sm = add(tree[id << 1].sm, tree[id << 1 | 1].sm);
}