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;
inline int add(int a, int b) {
  if ((a += b) >= mod) a -= mod;
  return a;
}
inline int mult(int a, int b) {
  long long t = 1ll * a * b;
  if (t >= mod) t %= mod;
  return t;
}
inline int power(int a, int b) {
  int out = 1;
  while (b) {
    if (b & 1) out = mult(out, a);
    a = mult(a, a);
    b >>= 1;
  }
  return out;
}
class segtree {
 public:
  int sum[800010], lzy[800010];
  void pushnow(int p, int v) {
    sum[p] = mult(sum[p], v);
    lzy[p] = mult(lzy[p], v);
  }
  void pushdown(int p) {
    if (lzy[p] != 1) {
      pushnow((p << 1), lzy[p]);
      pushnow(((p << 1) | 1), lzy[p]);
      lzy[p] = 1;
    }
  }
  void pushup(int p) { sum[p] = add(sum[(p << 1)], sum[((p << 1) | 1)]); }
  void build(int p, int l, int r) {
    lzy[p] = 1;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build((p << 1), l, mid);
    build(((p << 1) | 1), mid + 1, r);
  }
  void set(int p, int l, int r, int pos, int v) {
    if (l == r) {
      sum[p] = mult(lzy[p], v);
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (pos <= mid)
      set((p << 1), l, mid, pos, v);
    else
      set(((p << 1) | 1), mid + 1, r, pos, v);
    pushup(p);
  }
  void modify(int p, int l, int r, int ml, int mr, int v) {
    if (ml <= l && r <= mr) {
      pushnow(p, v);
      return;
    }
    pushdown(p);
    int mid = (l + r) >> 1;
    if (ml <= mid) modify((p << 1), l, mid, ml, mr, v);
    if (mr > mid) modify(((p << 1) | 1), mid + 1, r, ml, mr, v);
    pushup(p);
  }
  int query(int p, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return sum[p];
    pushdown(p);
    int mid = (l + r) >> 1, ret = 0;
    if (ql <= mid) ret = query((p << 1), l, mid, ql, qr);
    if (qr > mid) ret = add(ret, query(((p << 1) | 1), mid + 1, r, ql, qr));
    return ret;
  }
  int qlzy(int p, int l, int r, int pos) {
    if (l == r) return lzy[p];
    pushdown(p);
    int mid = (l + r) >> 1;
    if (pos <= mid) return qlzy((p << 1), l, mid, pos);
    return qlzy(((p << 1) | 1), mid + 1, r, pos);
  }
} T;
vector<int> t[200010];
int n, q, v[200010], opt[200010], x[200010], y[200010], pos[200010],
    nodecnt = 1, dfn[200010], tim, R[200010], siz[200010];
void dfs(int np) {
  dfn[np] = ++tim;
  for (int x : t[np]) dfs(x);
  R[np] = tim;
}
int main() {
  scanf("%d%d", &v[1], &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &opt[i]);
    if (opt[i] == 1) {
      scanf("%d%d", &x[i], &y[i]);
      pos[i] = ++nodecnt;
      t[x[i]].push_back(pos[i]);
    } else {
      scanf("%d", &x[i]);
    }
  }
  n = nodecnt;
  dfs(1);
  T.build(1, 1, n);
  T.set(1, 1, n, dfn[1], v[1]);
  siz[1] = 1;
  for (int i = 1; i <= q; i++) {
    if (opt[i] == 1) {
      T.modify(1, 1, n, dfn[x[i]], R[x[i]],
               mult(siz[x[i]] + 1, power(siz[x[i]], mod - 2)));
      siz[x[i]]++;
      siz[pos[i]] = 1;
      T.set(1, 1, n, dfn[pos[i]], y[i]);
    } else {
      printf("%d\n",
             mult(siz[x[i]], mult(T.query(1, 1, n, dfn[x[i]], R[x[i]]),
                                  power(T.qlzy(1, 1, n, dfn[x[i]]), mod - 2))));
    }
  }
  return 0;
}