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 chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
inline int fpm(long long b, int e, int m) {
  b %= m;
  long long t = 1;
  for (; e; e >>= 1, (b *= b) %= m)
    if (e & 1) (t *= b) %= m;
  return t;
}
const int Mod = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const int maxn = 200000;
int n;
struct node;
node *newnode();
struct node {
  node *c[2];
  int sum;
  int label;
  node() : sum(0), label(1) { memset(c, 0, sizeof c); }
  void update() {
    sum = 0;
    for (int i = (0), _end_ = (2); i < _end_; ++i)
      if (c[i]) (sum += c[i]->sum) %= Mod;
  }
  void flag_label(int _label) {
    label = (long long)label * _label % Mod;
    sum = (long long)sum * _label % Mod;
  }
  void push_down() {
    if (label) {
      for (int i = (0), _end_ = (2); i < _end_; ++i) c[i]->flag_label(label);
      label = 1;
    }
  }
};
const int max0 = 100000;
node *nd_pool;
int nd_res = 0;
node *newnode() {
  if (!nd_res) nd_pool = new node[max0], nd_res = max0;
  return nd_pool + (--nd_res);
}
node *rt;
int seg_x, seg_y, seg_z;
void add(node *&rt, int l, int r) {
  if (seg_x <= l && r <= seg_y) {
    rt->flag_label(seg_z);
    return;
  }
  int mid = (l + r) >> 1;
  rt->push_down();
  if (seg_x < mid) add(rt->c[0], l, mid);
  if (seg_y > mid) add(rt->c[1], mid, r);
  rt->update();
}
inline bool seg_add(int first, int second, int z) {
  if (first >= second) return 0;
  seg_x = first, seg_y = second, seg_z = z;
  add(rt, 0, n);
  return 1;
}
inline void query(node *rt, int l, int r) {
  if (seg_x <= l && r <= seg_y) {
    (seg_z += rt->sum) %= Mod;
    return;
  }
  int mid = (l + r) >> 1;
  rt->push_down();
  if (seg_x < mid) query(rt->c[0], l, mid);
  if (seg_y > mid) query(rt->c[1], mid, r);
}
inline int seg_query(int first, int second) {
  if (first >= second) return 0;
  seg_x = first, seg_y = second, seg_z = 0;
  query(rt, 0, n);
  return seg_z;
}
int pos[maxn + 5];
int v[maxn + 5];
inline void build(node *&rt, int l, int r) {
  rt = newnode();
  if (r - l <= 1) {
    rt->sum = v[pos[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build(rt->c[0], l, mid);
  build(rt->c[1], mid, r);
  rt->update();
}
struct edge {
  int id, nxt;
  edge() {}
  edge(int _id, int _nxt) : id(_id), nxt(_nxt) {}
};
edge e[maxn + 5];
int st[maxn + 5], en = 0;
inline void add_edge(int first, int second) {
  e[en] = edge(second, st[first]), st[first] = en++;
}
int dfn[maxn + 5], End[maxn + 5];
int tot = 0;
int w[maxn + 5];
int seq[maxn + 5], deg[maxn + 5];
int fa[maxn + 5];
void dfs(int first, int now) {
  pos[dfn[first] = tot++] = first;
  v[first] = (long long)w[first] * now % Mod;
  for (int i = st[first]; i != -1; i = e[i].nxt) {
    int second = e[i].id;
    dfs(second, (long long)now * deg[second] % Mod);
  }
  End[first] = tot;
}
int main() {
  memset(st, -1, sizeof st), en = 0;
  int m;
  scanf("%d%d", w, &m);
  n = 1;
  for (int i = (0), _end_ = (m); i < _end_; ++i) {
    int ty, p, v;
    scanf("%d", &ty);
    if (ty == 1)
      scanf("%d%d", &p, &v), --p, fa[n] = p, ++deg[p], add_edge(p, n),
                                  seq[i] = n << 1, w[n++] = v;
    else
      scanf("%d", &p), --p, seq[i] = p << 1 | 1;
  }
  for (int i = (0), _end_ = (n); i < _end_; ++i) ++deg[i];
  dfs(0, deg[0]);
  build(rt, 0, n);
  vector<int> ans;
  for (int i = m - 1; i >= 0; --i) {
    int first = seq[i] >> 1;
    if (seq[i] & 1) {
      int tmp = seg_query(dfn[first], dfn[first] + 1);
      int tmp0 = seg_query(dfn[first], End[first]);
      tmp = (long long)tmp * fpm(w[first], Mod - 2, Mod) % Mod *
            fpm(deg[first], Mod - 2, Mod) % Mod;
      ans.push_back((long long)tmp0 * fpm(tmp, Mod - 2, Mod) % Mod);
    } else {
      seg_add(dfn[first], dfn[first] + 1, 0);
      first = fa[first];
      int lyc =
          (long long)(deg[first] - 1) * fpm(deg[first], Mod - 2, Mod) % Mod;
      --deg[first];
      seg_add(dfn[first], End[first], lyc);
    }
  }
  reverse((ans).begin(), (ans).end());
  for (auto it : ans) printf("%d\n", it);
  return 0;
}