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>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG = 20;
long long n = 1, m, k, u, v, x, y, a, b;
long long seg[MAXN << 2], lazy[MAXN << 2];
long long ans[MAXN];
int typ[MAXN], V[MAXN];
int sz[MAXN];
long long W[MAXN];
int par[MAXN];
int stt[MAXN], fnt[MAXN], timer = 1;
vector<int> G[MAXN];
long long powmod(long long a, long long b) {
  if (!b) return 1;
  if (b & 1) return a * powmod(a * a % mod, b >> 1) % mod;
  return powmod(a * a % mod, b >> 1);
}
long long inv(long long x) { return powmod(x, mod - 2); }
inline long long _mul(long long a, long long b) { return a * b % mod; }
void add_lazy(int id, long long val) {
  seg[id] = _mul(seg[id], val);
  lazy[id] = _mul(lazy[id], val);
}
void shift(int id) {
  if (lazy[id] == 1) return;
  add_lazy(id << 1, lazy[id]);
  add_lazy(id << 1 | 1, lazy[id]);
  lazy[id] = 1;
}
void Mul(int id, int tl, int tr, int l, int r, long long val) {
  if (r <= tl || tr <= l) return;
  if (l <= tl && tr <= r) {
    add_lazy(id, val);
    return;
  }
  shift(id);
  int mid = (tl + tr) >> 1;
  Mul(id << 1, tl, mid, l, r, val);
  Mul(id << 1 | 1, mid, tr, l, r, val);
  seg[id] = (seg[id << 1] + seg[id << 1 | 1]) % mod;
}
void Set(int id, int tl, int tr, int pos, int val) {
  if (tr - tl == 1) {
    seg[id] = val;
    return;
  }
  shift(id);
  int mid = (tl + tr) >> 1;
  if (pos < mid)
    Set(id << 1, tl, mid, pos, val);
  else
    Set(id << 1 | 1, mid, tr, pos, val);
  seg[id] = (seg[id << 1] + seg[id << 1 | 1]) % mod;
}
long long Get(int id, int tl, int tr, int l, int r) {
  if (r <= tl || tr <= l) return 0;
  if (l <= tl && tr <= r) return seg[id];
  shift(id);
  int mid = (tl + tr) >> 1;
  return (Get(id << 1, tl, mid, l, r) + Get(id << 1 | 1, mid, tr, l, r)) % mod;
}
void dfs(int node) {
  stt[node] = timer++;
  for (int v : G[node])
    if (v != par[node]) dfs(v);
  fnt[node] = timer;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  fill(lazy, lazy + MAXN * 4, 1);
  cin >> W[1] >> m;
  sz[1] = 1;
  for (int i = 1; i <= m; i++) {
    cin >> typ[i];
    if (typ[i] == 2)
      cin >> V[i];
    else {
      V[i] = ++n;
      cin >> par[n] >> W[n];
      G[par[n]].push_back(n);
      sz[n] = 1;
      sz[par[n]]++;
    }
  }
  dfs(1);
  for (int i = 1; i <= n; i++) Set(1, 1, n + 1, stt[i], W[i]);
  for (int i = 1; i <= n; i++) Mul(1, 1, n + 1, stt[i], fnt[i], sz[i]);
  for (int i = m; i; i--) {
    if (typ[i] == 1) {
      Set(1, 1, n + 1, stt[V[i]], 0);
      int tmp = par[V[i]];
      Mul(1, 1, n + 1, stt[tmp], fnt[tmp], inv(sz[tmp]));
      sz[tmp]--;
      Mul(1, 1, n + 1, stt[tmp], fnt[tmp], sz[tmp]);
      continue;
    }
    long long tmp = Get(1, 1, n + 1, stt[V[i]], fnt[V[i]]);
    tmp = tmp * inv(Get(1, 1, n + 1, stt[V[i]], stt[V[i]] + 1)) % mod;
    tmp = tmp * W[V[i]] % mod;
    tmp = tmp * sz[V[i]] % mod;
    ans[i] = tmp;
  }
  for (int i = 1; i <= m; i++)
    if (typ[i] == 2) cout << ans[i] << '\n';
  return 0;
}