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 maxn = 2e5 * 4, mod = 1e9 + 7;
struct Node {
  long long sum;
  long long cnt;
  long long mul;
};
Node tree[maxn];
int numBg[maxn], numEn[maxn];
int d[maxn];
int sz = 1;
void Down(int v) {
  (tree[2 * v].sum *= tree[v].mul) %= mod;
  (tree[2 * v + 1].sum *= tree[v].mul) %= mod;
  (tree[2 * v].cnt *= tree[v].mul) %= mod;
  (tree[2 * v + 1].cnt *= tree[v].mul) %= mod;
  (tree[2 * v].mul *= tree[v].mul) %= mod;
  (tree[2 * v + 1].mul *= tree[v].mul) %= mod;
  tree[v].mul = 1;
}
long long int sum(int v, int vl, int vr, int l, int r) {
  if (l <= vl && vr <= r) {
    return tree[v].sum;
  } else if (r <= vl || vr <= l) {
    return 0;
  }
  Down(v);
  int vm = (vl + vr) / 2;
  return (sum(2 * v, vl, vm, l, r) + sum(2 * v + 1, vm, vr, l, r)) % mod;
}
long long mpow(long long int x, int p) {
  if (p == 0) return 1;
  if (p == 1) return x;
  if (p % 2 == 0) {
    long long px = mpow(x, p / 2);
    return (px * px) % mod;
  } else {
    return (mpow(x, p - 1) * x) % mod;
  }
}
void mull(int v, int x) {
  if (x - 1 != 0) tree[v].sum *= mpow(x - 1, mod - 2);
  tree[v].sum %= mod;
  tree[v].sum *= x;
  tree[v].sum %= mod;
  if (x - 1 != 0) tree[v].cnt *= mpow(x - 1, mod - 2);
  tree[v].cnt %= mod;
  tree[v].cnt *= x;
  tree[v].cnt %= mod;
  if (x - 1 != 0) tree[v].mul *= mpow(x - 1, mod - 2);
  tree[v].mul %= mod;
  tree[v].mul *= x;
  tree[v].mul %= mod;
  return;
}
void NewVal(int v) {
  (tree[v].sum = tree[2 * v].sum + tree[2 * v + 1].sum) %= mod;
  (tree[v].cnt = tree[2 * v].cnt + tree[2 * v + 1].cnt) %= mod;
}
void update(int v, int vl, int vr, int l, int r, int x) {
  if (l <= vl && vr <= r) {
    mull(v, x);
    return;
  } else if (r <= vl || vr <= l) {
    return;
  }
  Down(v);
  int vm = (vl + vr) / 2;
  update(2 * v, vl, vm, l, r, x);
  update(2 * v + 1, vm, vr, l, r, x);
  NewVal(v);
}
long long valCnt(int v) {
  int u = 1;
  int pos = v;
  v += sz;
  int l = 0, r = sz;
  while (u != v) {
    Down(u);
    int m = (l + r) / 2;
    if (pos < m) {
      r = m;
      u = 2 * u;
    } else {
      l = m;
      u = 2 * u + 1;
    }
  }
  return tree[v].cnt;
}
void newV(int v, int x, long long ml) {
  valCnt(v);
  v = v + sz;
  ml = tree[v].mul;
  (tree[v].sum = x * ml) %= mod;
  tree[v].cnt = ml;
  tree[v].mul = ml;
  v /= 2;
  while (v > 0) {
    tree[v].sum = tree[2 * v].sum + tree[2 * v + 1].sum;
    tree[v].sum %= mod;
    tree[v].cnt = tree[2 * v].cnt + tree[2 * v + 1].cnt;
    tree[v].cnt %= mod;
    v /= 2;
  }
}
vector<int> G[maxn];
int used[maxn];
int p[maxn];
int cnt = 0;
struct que {
  int fl, p, val, v;
};
vector<que> qu;
int pos = 0;
void dfs(int v) {
  numBg[v] = pos;
  ++pos;
  for (int i = 0; i < (int)G[v].size(); ++i) {
    int u = G[v][i];
    dfs(u);
  }
  numEn[v] = pos;
}
void Print() {
  for (int i = sz; i < 2 * sz; ++i) {
    cerr << tree[i].sum << " " << tree[i].cnt << " " << tree[i].mul << endl;
  }
  cerr << "---------";
}
int main() {
  int v, q;
  scanf("%d%d", &v, &q);
  qu.resize(q);
  int last = 1;
  for (int i = 0; i < q; ++i) {
    scanf("%d%d", &qu[i].fl, &qu[i].p);
    --qu[i].p;
    if (qu[i].fl == 1) {
      scanf("%d", &qu[i].val);
      G[qu[i].p].push_back(last);
      qu[i].v = last;
      p[last] = qu[i].p;
      ++last;
    }
  }
  dfs(0);
  while (sz < pos) {
    sz *= 2;
  }
  for (int i = 1; i < 2 * sz; ++i) {
    tree[i].mul = 1;
  }
  newV(0, v, 1);
  d[0] = 1;
  for (int i = 0; i < q; ++i) {
    if (qu[i].fl == 1) {
      d[qu[i].p]++;
      d[qu[i].v] = 1;
      update(1, 0, sz, numBg[qu[i].p], numEn[qu[i].p], d[qu[i].p]);
      newV(numBg[qu[i].v], qu[i].val, 1);
    } else {
      printf(
          "%d\n",
          (int)((sum(1, 0, sz, numBg[qu[i].p], numEn[qu[i].p]) *
                 mpow(qu[i].p > 0 ? valCnt(numBg[p[qu[i].p]]) : 1, mod - 2)) %
                mod));
    }
  }
}