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 oo = 0x3f3f3f3f;
template <class T>
void parr(T *a, T *b) {
  for (T *i = a; i < b; ++i) cout << *i << ' ';
}
template <typename T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <typename T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
const int maxN = 2e5 + 5, mo = 1e9 + 7;
struct Edge {
  int v, next;
  Edge() {}
  Edge(int v, int next) : v(v), next(next) {}
} G[maxN << 1];
int st[maxN], e;
void addedge(int u, int v) {
  G[++e] = Edge(v, st[u]);
  st[u] = e;
}
int pow_mod(int x, int t) {
  int ret = 1;
  while (t) {
    if (t & 1) ret = (long long)ret * x % mo;
    x = (long long)x * x % mo;
    t >>= 1;
  }
  return ret;
}
pair<int, int> opt[maxN];
namespace seg {
int lazy[maxN << 2], sum[maxN << 2];
void build(int now, int l, int r) {
  lazy[now] = 1;
  if (l == r) return;
  build((now << 1), l, ((l + r) >> 1));
  build(((now << 1) | 1), ((l + r) >> 1) + 1, r);
}
inline void pushdown(int x) {
  if (lazy[x]) {
    int &k = lazy[x];
    lazy[(x << 1)] = (long long)lazy[(x << 1)] * k % mo;
    lazy[((x << 1) | 1)] = (long long)lazy[((x << 1) | 1)] * k % mo;
    sum[(x << 1)] = (long long)sum[(x << 1)] * k % mo;
    sum[((x << 1) | 1)] = (long long)sum[((x << 1) | 1)] * k % mo;
    k = 1;
  }
}
inline void update(int now) {
  sum[now] = (sum[(now << 1)] + sum[((now << 1) | 1)]) % mo;
}
int ql, qr, val;
void modify(int now, int l, int r) {
  if (l == r) {
    ;
    sum[now] = (long long)lazy[now] * val % mo;
    return;
  }
  pushdown(now);
  if (ql <= ((l + r) >> 1))
    modify((now << 1), l, ((l + r) >> 1));
  else
    modify(((now << 1) | 1), ((l + r) >> 1) + 1, r);
  update(now);
  ;
}
void mul(int now, int l, int r) {
  if (ql <= l && qr >= r) {
    sum[now] = (long long)sum[now] * val % mo;
    lazy[now] = (long long)lazy[now] * val % mo;
    return;
  }
  pushdown(now);
  if (ql <= ((l + r) >> 1)) mul((now << 1), l, ((l + r) >> 1));
  if (qr > ((l + r) >> 1)) mul(((now << 1) | 1), ((l + r) >> 1) + 1, r);
  update(now);
}
int get_sum(int now, int l, int r) {
  if (ql <= l && qr >= r) return sum[now];
  pushdown(now);
  int ret = 0;
  if (ql <= ((l + r) >> 1)) ret = get_sum((now << 1), l, ((l + r) >> 1));
  if (qr > ((l + r) >> 1))
    ret += get_sum(((now << 1) | 1), ((l + r) >> 1) + 1, r);
  ;
  ;
  return ret % mo;
}
int get_lazy(int now, int l, int r) {
  if (l == r) return lazy[now];
  pushdown(now);
  if (ql <= ((l + r) >> 1))
    return get_lazy((now << 1), l, ((l + r) >> 1));
  else
    return get_lazy(((now << 1) | 1), ((l + r) >> 1) + 1, r);
}
}  // namespace seg
int N;
int w[maxN], dfs_clock, fa[maxN], deg[maxN];
pair<int, int> lover[maxN];
void dfs(int x, int fr) {
  ;
  lover[x].first = ++dfs_clock;
  fa[x] = fr;
  for (int e = st[x]; e; e = G[e].next)
    if (G[e].v != fr) dfs(G[e].v, x);
  lover[x].second = dfs_clock;
}
int Q;
void init() {
  scanf("%d%d", &w[1], &Q);
  N = 1;
  for (int i = (1); i <= (Q); ++i) {
    scanf("%d", &opt[i].first);
    if (opt[i].first == 1) {
      scanf("%d", &opt[i].second);
      scanf("%d", &w[++N]);
      addedge(N, opt[i].second);
      addedge(opt[i].second, N);
      opt[i].second = N;
    } else {
      scanf("%d", &opt[i].second);
    }
  }
  dfs(1, 0);
  seg::build(1, 1, N);
}
void solve() {
  seg::ql = seg::qr = 1;
  seg::val = w[1];
  deg[1] = 1;
  seg::modify(1, 1, N);
  for (int i = (1); i <= (Q); ++i) {
    if (opt[i].first == 1) {
      int x = opt[i].second;
      seg::ql = lover[fa[x]].first;
      seg::qr = lover[fa[x]].second;
      seg::val =
          (long long)(pow_mod(deg[fa[x]], mo - 2)) * (deg[fa[x]] + 1) % mo;
      deg[fa[x]]++;
      seg::mul(1, 1, N);
      seg::val = w[x];
      seg::ql = seg::qr = lover[x].first;
      seg::modify(1, 1, N);
      deg[x] = 1;
    } else {
      int x = opt[i].second;
      seg::ql = lover[x].first;
      seg::qr = lover[x].second;
      int ans = seg::get_sum(1, 1, N);
      if (x != 1) {
        seg::ql = lover[fa[x]].first;
        seg::qr = lover[fa[x]].first;
        int t = seg::get_lazy(1, 1, N);
        ans = (long long)ans * (pow_mod(t, mo - 2)) % mo;
      }
      printf("%d\n", ans);
    }
  }
}
int main() {
  init();
  solve();
  return 0;
}