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;
long long tree[(1 << 20)], mod = 1e9 + 7;
long long lazy[(1 << 20)];
vector<long long> graph[200009];
long long seg[2][200009];
long long arr[200009];
long long par[200009];
long long children[200009];
long long j = 1;
void dfs(long long i) {
  seg[0][i] = j++;
  for (long long f = 0; f < graph[i].size(); f++) dfs(graph[i][f]);
  seg[1][i] = j - 1;
}
long long getsum(long long l, long long r, long long a, long long b,
                 long long i) {
  if (l != r) {
    lazy[i * 2] = (lazy[i] * lazy[i * 2]) % mod;
    lazy[i * 2 + 1] = (lazy[i] * lazy[i * 2 + 1]) % mod;
  }
  tree[i] = (lazy[i] * tree[i]) % mod;
  lazy[i] = 1;
  if (l >= a && r <= b) return tree[i];
  if (l > b || r < a) return 0;
  return (getsum(l, (l + r) / 2, a, b, i * 2) +
          getsum((l + r) / 2 + 1, r, a, b, i * 2 + 1)) %
         mod;
}
void update(long long l, long long r, long long a, long long b, long long i,
            long long x) {
  if (l != r) {
    lazy[i * 2] = (lazy[i] * lazy[i * 2]) % mod;
    lazy[i * 2 + 1] = (lazy[i] * lazy[i * 2 + 1]) % mod;
  }
  tree[i] = (lazy[i] * tree[i]) % mod;
  lazy[i] = 1;
  if (l >= a && r <= b) {
    lazy[i] = x;
    if (l != r) {
      lazy[i * 2] = (lazy[i] * lazy[i * 2]) % mod;
      lazy[i * 2 + 1] = (lazy[i] * lazy[i * 2 + 1]) % mod;
    }
    tree[i] = (lazy[i] * tree[i]) % mod;
    lazy[i] = 1;
    return;
  }
  if (l > b || r < a) return;
  update(l, (l + r) / 2, a, b, i * 2, x);
  update((l + r) / 2 + 1, r, a, b, i * 2 + 1, x);
  tree[i] = (tree[i * 2] + tree[i * 2 + 1]) % mod;
}
void update2(long long l, long long r, long long a, long long b, long long i,
             long long x) {
  if (l != r) {
    lazy[i * 2] = (lazy[i] * lazy[i * 2]) % mod;
    lazy[i * 2 + 1] = (lazy[i] * lazy[i * 2 + 1]) % mod;
  }
  tree[i] = (lazy[i] * tree[i]) % mod;
  lazy[i] = 1;
  if (l >= a && r <= b) {
    tree[i] = x;
    return;
  }
  if (l > b || r < a) return;
  update2(l, (l + r) / 2, a, b, i * 2, x);
  update2((l + r) / 2 + 1, r, a, b, i * 2 + 1, x);
  tree[i] = (tree[i * 2] + tree[i * 2 + 1]) % mod;
}
void update1(long long i, long long x) {
  update2(0, (1 << 19) - 1, i, i, 1, x);
}
long long pwr(long long b, long long p) {
  if (p == 0) return 1;
  if (p % 2) return (b * pwr(b, p - 1)) % mod;
  return pwr((b * b) % mod, p / 2);
}
int main() {
  for (long long f = 0; f < (1 << 20); f++) lazy[f] = 1;
  vector<pair<long long, long long> > v;
  long long x, q;
  cin >> x >> q;
  arr[1] = x;
  update1(1, x);
  long long i = 2;
  for (long long f = 0; f < q; f++) {
    long long a, b, c;
    cin >> a >> b;
    if (a == 1) {
      cin >> c;
      graph[b].push_back(i);
      par[i] = b;
      arr[i] = c;
      v.push_back(make_pair(a, i++));
    } else {
      v.push_back(make_pair(a, b));
    }
  }
  dfs(1);
  for (long long f = 0; f < q; f++) {
    if (v[f].first == 1) {
      update(0, (1 << 19) - 1, seg[0][par[v[f].second]],
             seg[1][par[v[f].second]], 1,
             ((children[par[v[f].second]] + 2) *
              pwr(children[par[v[f].second]] + 1, mod - 2)) %
                 mod);
      update1(seg[0][v[f].second],
              (((getsum(0, (1 << 19) - 1, seg[0][par[v[f].second]],
                        seg[0][par[v[f].second]], 1) *
                 arr[v[f].second]) %
                mod) *
               pwr(arr[par[v[f].second]], mod - 2)) %
                  mod);
      children[par[v[f].second]]++;
    } else {
      long long scale = 1;
      if (v[f].second != 1) {
        scale = (getsum(0, (1 << 19) - 1, seg[0][par[v[f].second]],
                        seg[0][par[v[f].second]], 1) *
                 pwr(arr[par[v[f].second]], mod - 2)) %
                mod;
      }
      cout << (getsum(0, (1 << 19) - 1, seg[0][v[f].second],
                      seg[1][v[f].second], 1) *
               pwr(scale, mod - 2)) %
                  mod
           << endl;
    }
  }
}