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 long long maxN = 2e5 + 7;
const long long segN = 8e5 + 7;
const long long moD = 1e9 + 7;
struct query {
  long long t, x, y;
};
long long n;
long long st[maxN], fi[maxN], sum[segN], deg[maxN], mul[segN], laz[segN],
    val[maxN];
vector<long long> chi[maxN];
vector<query> que;
long long wop(long long x, long long y) {
  if (y == 0) return 1;
  long long res = wop(x, y / 2);
  return res * res % moD * (y % 2 == 1 ? x : 1) % moD;
}
long long dfs(long long v) {
  fi[v] = st[v] + 1;
  for (long long u : chi[v]) {
    st[u] = fi[v];
    fi[v] = dfs(u);
  }
  return fi[v];
}
void merge(long long x) { sum[x] = (sum[x << 1] + sum[x << 1 | 1]) % moD; }
void upd(long long x, long long val) {
  sum[x] = sum[x] * val % moD;
  mul[x] = mul[x] * val % moD;
  laz[x] = laz[x] * val % moD;
}
void shift(long long x) {
  upd(x << 1, laz[x]);
  upd(x << 1 | 1, laz[x]);
  laz[x] = 1;
}
void add(long long idx, long long val, long long x = 1, long long xl = 0,
         long long xr = n) {
  if (xr - xl == 1) {
    sum[x] = (sum[x] + val) % moD;
    return;
  }
  long long xm = (xl + xr) >> 1;
  shift(x);
  if (idx < xm)
    add(idx, val, x << 1, xl, xm);
  else
    add(idx, val, x << 1 | 1, xm, xr);
  merge(x);
}
void mult(long long ql, long long qr, long long qv, long long x = 1,
          long long xl = 0, long long xr = n) {
  if (xl >= qr || xr <= ql) return;
  if (ql <= xl && qr >= xr) {
    sum[x] = sum[x] * qv % moD;
    laz[x] = laz[x] * qv % moD;
    mul[x] = mul[x] * qv % moD;
    return;
  }
  shift(x);
  long long xm = (xl + xr) >> 1;
  mult(ql, qr, qv, x << 1, xl, xm);
  mult(ql, qr, qv, x << 1 | 1, xm, xr);
  merge(x);
}
long long get_mul(long long idx, long long x = 1, long long xl = 0,
                  long long xr = n) {
  if (xr - xl == 1) return mul[x];
  long long xm = (xl + xr) >> 1;
  shift(x);
  if (idx < xm) return get_mul(idx, x << 1, xl, xm);
  return get_mul(idx, x << 1 | 1, xm, xr);
}
long long get_sum(long long ql, long long qr, long long x = 1, long long xl = 0,
                  long long xr = n) {
  if (xl >= qr || xr <= ql) return 0;
  if (ql <= xl && qr >= xr) return sum[x];
  long long xm = (xl + xr) >> 1;
  shift(x);
  long long res = 0;
  res += get_sum(ql, qr, x << 1, xl, xm);
  res += get_sum(ql, qr, x << 1 | 1, xm, xr);
  return res % moD;
}
long long inv(long long x) { return wop(x, moD - 2); }
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long q;
  cin >> val[0] >> q;
  que.resize(q);
  for (long long i = 0; i < q; ++i) {
    cin >> que[i].t >> que[i].x;
    que[i].x--;
    if (que[i].t == 1) {
      n++;
      cin >> que[i].y;
      chi[que[i].x].push_back(n);
      val[n] = que[i].y;
    }
  }
  n++;
  for (long long i = 0; i < segN; ++i) laz[i] = mul[i] = 1;
  dfs(0);
  mul[0] = deg[0] = 1;
  add(st[0], val[0]);
  long long c = 0;
  for (long long i = 0; i < q; ++i) {
    long long v = que[i].x;
    if (que[i].t == 1) {
      c++;
      deg[c] = 1;
      mult(st[v], fi[v], inv(deg[v]) * (deg[v] + 1) % moD);
      deg[v]++;
      add(st[c], val[c] * get_mul(st[c]) % moD);
    } else
      cout << get_sum(st[v], fi[v]) * inv(get_mul(st[v])) % moD * deg[v] % moD
           << "\n";
  }
}