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;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1ll;
  long long _tmp = mypow(_a, _x / 2, _mod);
  _tmp = (_tmp * _tmp) % _mod;
  if (_x & 1) _tmp = (_tmp * _a) % _mod;
  return _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x + _y;
  if (_ >= _mod) _ -= _mod;
  return _;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x - _y;
  if (_ < 0) _ += _mod;
  return _;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x * _y;
  if (_ >= _mod) _ %= _mod;
  return _;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, _cs;
long long st[262144 << 1], vl[262144 << 1], mt[262144 << 1];
long long tagm[262144 << 1];
void build_st(int no, int l, int r) {
  tagm[no] = mt[no] = 1ll;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build_st((no << 1), l, mid);
  build_st((1 + (no << 1)), mid + 1, r);
}
void push(int no, int l, int r) {
  if (tagm[no] == 1) return;
  int mid = (l + r) >> 1;
  if (l == mid)
    mt[(no << 1)] = mul(mt[(no << 1)], tagm[no]);
  else
    tagm[(no << 1)] = mul(tagm[(no << 1)], tagm[no]);
  if (mid + 1 == r)
    mt[(1 + (no << 1))] = mul(mt[(1 + (no << 1))], tagm[no]);
  else
    tagm[(1 + (no << 1))] = mul(tagm[(1 + (no << 1))], tagm[no]);
  st[(no << 1)] = mul(st[(no << 1)], tagm[no]);
  st[(1 + (no << 1))] = mul(st[(1 + (no << 1))], tagm[no]);
  tagm[no] = 1;
}
void pull(int no, int l, int r) {
  st[no] = add(st[(no << 1)], st[(1 + (no << 1))]);
}
void modify_vl(int no, int l, int r, int pos, long long _vl) {
  push(no, l, r);
  if (l == r) {
    vl[no] = _vl;
    st[no] = mul(_vl, mt[no]);
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify_vl((no << 1), l, mid, pos, _vl);
  else
    modify_vl((1 + (no << 1)), mid + 1, r, pos, _vl);
  pull(no, l, r);
}
void modify_mt(int no, int l, int r, int ql, int qr, long long multi) {
  push(no, l, r);
  if (l == ql && r == qr) {
    if (l == r)
      mt[no] = mul(mt[no], multi);
    else
      tagm[no] = mul(tagm[no], multi);
    st[no] = mul(st[no], multi);
    return;
  }
  int mid = (l + r) >> 1;
  if (qr <= mid)
    modify_mt((no << 1), l, mid, ql, qr, multi);
  else if (mid < ql)
    modify_mt((1 + (no << 1)), mid + 1, r, ql, qr, multi);
  else {
    modify_mt((no << 1), l, mid, ql, mid, multi);
    modify_mt((1 + (no << 1)), mid + 1, r, mid + 1, qr, multi);
  }
  pull(no, l, r);
}
long long query(int no, int l, int r, int ql, int qr) {
  push(no, l, r);
  if (l == ql && r == qr) return st[no];
  int mid = (l + r) >> 1;
  if (qr <= mid) return query((no << 1), l, mid, ql, qr);
  if (mid < ql) return query((1 + (no << 1)), mid + 1, r, ql, qr);
  return add(query((no << 1), l, mid, ql, mid),
             query((1 + (no << 1)), mid + 1, r, mid + 1, qr));
}
long long querym(int no, int l, int r, int pos) {
  push(no, l, r);
  if (l == r) return mt[no];
  int mid = (l + r) >> 1;
  if (pos <= mid) return querym((no << 1), l, mid, pos);
  return querym((1 + (no << 1)), mid + 1, r, pos);
}
int in[262144], out[262144], tidx;
vector<int> v[262144];
long long a[262144], deg[262144], inv[262144];
int q, tp[262144], qq[262144][3];
void build() {
  for (int i = 1; i < 262144; i++)
    inv[i] = mypow(i, 1000000007ll - 2, 1000000007ll);
}
void DFS(int now) {
  in[now] = ++tidx;
  for (int i = 0; i < (int)v[now].size(); i++) DFS(v[now][i]);
  out[now] = tidx;
}
int n;
void init() {
  a[1] = getint();
  q = getint();
  int nidx = 1;
  deg[1] = 1;
  for (int i = 1; i <= q; i++) {
    tp[i] = getint();
    for (int j = 0; j <= 2 - tp[i]; j++) qq[i][j] = getint();
    if (tp[i] == 1) {
      v[qq[i][0]].push_back(++nidx);
      qq[i][2] = nidx;
    }
  }
  n = nidx;
  build_st(1, 1, n);
  DFS(1);
  modify_vl(1, 1, n, in[1], a[1]);
}
void solve() {
  for (int i = 1; i <= q; i++) {
    if (tp[i] == 1) {
      int prt = qq[i][0];
      int avl = qq[i][1];
      int x = qq[i][2];
      long long mdlt = mul(deg[prt] + 1, inv[deg[prt]]);
      modify_vl(1, 1, n, in[x], avl);
      modify_mt(1, 1, n, in[prt], out[prt], mdlt);
      deg[x] = 1;
      deg[prt]++;
    } else {
      int x = qq[i][0];
      long long tans = query(1, 1, n, in[x], out[x]);
      tans = mul(tans, mul(deg[x], mypow(querym(1, 1, n, in[x]),
                                         1000000007ll - 2, 1000000007ll)));
      printf("%lld\n", tans);
    }
  }
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}