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 = (int)1e9 + 7;
template <class X, class Y>
void minimize(X &x, const Y &y) {
  if (x > y) x = y;
}
template <class X, class Y>
void maximize(X &x, const Y &y) {
  if (x < y) x = y;
}
int inv[400400];
int inverseValue(int x) {
  int res = 1;
  int mul = x;
  int k = mod - 2;
  while (k > 0) {
    if (k & 1) res = 1LL * res * mul % mod;
    mul = 1LL * mul * mul % mod;
    k >>= 1;
  }
  return (res);
}
void precount(void) {
  for (int i = (1), _b = (400400 - 1); i <= _b; i = i + 1)
    inv[i] = inverseValue(i);
}
int inverse(int x) { return (x < 400400 ? inv[x] : inverseValue(x)); }
class FenwickTree {
  vector<int> v;
  int n;
  void updateAdd(int x, int d) {
    assert(x > 0);
    for (; x <= n; x += x & -x) v[x] = (v[x] + d) % mod;
  }
  int getAdd(int x) const {
    int res = 0;
    for (; x >= 1; x &= x - 1) res = (res + v[x]) % mod;
    return (res);
  }
  void updateMul(int x, int d) {
    assert(x > 0);
    for (; x <= n; x += x & -x) v[x] = 1LL * v[x] * d % mod;
  }
  int getMul(int x) const {
    int res = 1;
    for (; x >= 1; x &= x - 1) res = 1LL * res * v[x] % mod;
    return (res);
  }

 public:
  FenwickTree() { n = 0; }
  FenwickTree(int n, int init) {
    this->n = n;
    v.assign(n + 7, init);
  }
  void update(int x, int d) { updateAdd(x, d); }
  void updateRange(int l, int r, int d) {
    updateMul(l, d);
    if (r < n) updateMul(r + 1, inverse(d));
  }
  int get(int x) const { return (getMul(x)); }
  int getRange(int l, int r) const {
    return (l == 1 ? getAdd(r) : (getAdd(r) - getAdd(l - 1) + mod) % mod);
  }
};
class SegmentTree {
 private:
  vector<int> tree, lazy;
  int n;
  void pushdown(int i) {
    for (int j = (2 * i), _b = (2 * i + 1); j <= _b; j = j + 1) {
      tree[j] = 1LL * tree[j] * lazy[i] % mod;
      lazy[j] = 1LL * lazy[j] * lazy[i] % mod;
    }
    lazy[i] = 1;
  }
  void updateAdd(int i, int l, int r, int x, int v) {
    if (l == r) {
      tree[i] = (tree[i] + v) % mod;
      return;
    }
    pushdown(i);
    int m = (l + r) >> 1;
    if (x > m)
      updateAdd(2 * i + 1, m + 1, r, x, v);
    else
      updateAdd(2 * i, l, m, x, v);
    tree[i] = (tree[2 * i] + tree[2 * i + 1]) % mod;
  }
  int getSum(int i, int l, int r, int u, int v) {
    if (l > v || r < u || l > r || v < u) return (0);
    if (u <= l && r <= v) return (tree[i]);
    pushdown(i);
    int m = (l + r) >> 1;
    int L = getSum(2 * i, l, m, u, v);
    int R = getSum(2 * i + 1, m + 1, r, u, v);
    return ((L + R) % mod);
  }
  void updateMul(int i, int l, int r, int u, int v, int x) {
    if (l > v || r < u || l > r || v < u) return;
    if (u <= l && r <= v) {
      tree[i] = 1LL * tree[i] * x % mod;
      lazy[i] = 1LL * lazy[i] * x % mod;
      return;
    }
    pushdown(i);
    int m = (l + r) >> 1;
    updateMul(2 * i, l, m, u, v, x);
    updateMul(2 * i + 1, m + 1, r, u, v, x);
    tree[i] = (tree[2 * i] + tree[2 * i + 1]) % mod;
  }

 public:
  SegmentTree() { n = 0; }
  SegmentTree(int n) {
    this->n = n;
    tree.assign(4 * n + 7, 0);
    lazy.assign(4 * n + 7, 1);
  }
  void updateMul(int l, int r, int v) { updateMul(1, 1, n, l, r, v); }
  void updateAdd(int x, int v) { updateAdd(1, 1, n, x, v); }
  int getSum(int l, int r) { return (getSum(1, 1, n, l, r)); }
};
struct Query {
  int type, par, child, val;
  Query() { type = par = child = val = 0; }
  Query(int t, int p, int c, int v) {
    type = t;
    par = p;
    child = c;
    val = v;
  }
};
Query query[400400];
vector<int> child[400400];
int val[400400], mul[400400], sta[400400], fin[400400], par[400400];
int n, q, cnt;
FenwickTree bitMul;
SegmentTree bitVal;
void init(void) {
  scanf("%d%d", &val[1], &q);
  n = 1;
  for (int i = (1), _b = (q); i <= _b; i = i + 1) {
    int type, node;
    scanf("%d%d", &type, &node);
    if (type == 1) {
      int tmp;
      scanf("%d", &tmp);
      query[i] = Query(type, node, ++n, tmp);
      par[n] = node;
      val[n] = tmp;
      child[node].push_back(n);
    } else
      query[i] = Query(type, node, -1, -1);
  }
}
void dfs(int u) {
  sta[u] = ++cnt;
  for (__typeof((child[u]).begin()) it = (child[u]).begin();
       it != (child[u]).end(); it++)
    dfs(*it);
  fin[u] = cnt;
}
void prepare(void) {
  dfs(1);
  mul[1] = 1;
  bitMul = FenwickTree(n, 1);
  bitVal = SegmentTree(n);
  bitVal.updateAdd(sta[1], val[1]);
}
void addNode(int parent, int child) {
  mul[parent]++;
  mul[child] = 1;
  bitMul.updateRange(sta[parent], fin[parent],
                     1LL * mul[parent] * inverse(mul[parent] - 1) % mod);
  bitVal.updateMul(sta[parent], fin[parent],
                   1LL * mul[parent] * inverse(mul[parent] - 1) % mod);
  bitVal.updateAdd(sta[child], 1LL * val[child] * bitMul.get(sta[child]) % mod);
}
int answer(int u) {
  int res = bitVal.getSum(sta[u], fin[u]);
  if (u != 1) res = 1LL * res * inverse(bitMul.get(sta[par[u]])) % mod;
  return (res);
}
void process(void) {
  for (int i = (1), _b = (q); i <= _b; i = i + 1) {
    if (query[i].type == 1)
      addNode(query[i].par, query[i].child);
    else
      printf("%d\n", answer(query[i].par));
  }
}
int main(void) {
  precount();
  init();
  prepare();
  process();
  return 0;
}