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;
template <typename T>
inline void next_int(T &x) {
  x = 0;
  char c;
  bool neg = false;
  while (!isdigit(c = getchar()))
    if (c == '-') neg = true;
  do x = x * 10 + c - 48;
  while (isdigit(c = getchar()));
  if (neg) x = -x;
}
template <typename T>
inline void write_int(T x, char last = 0) {
  if (x < 0) putchar('-'), x = abs(x);
  char tmp[20];
  int cnt = 0;
  while (x >= 10) tmp[cnt++] = x % 10 + 48, x /= 10;
  tmp[cnt] = x + 48;
  for (int i = (cnt); i >= (0); --i) putchar(tmp[i]);
  if (last) putchar(last);
}
const long long base = (long long)1e9 + 7;
class SegTree {
 private:
  struct node {
    long long sum, lazy, mul;
  };
  node tree[1 << 19];
  inline void lazy_update(int k, int l, int r) {
    if (tree[k].lazy == 1) return;
    tree[k].sum = (tree[k].sum * tree[k].lazy) % base;
    if (l == r) tree[k].mul = (tree[k].mul * tree[k].lazy) % base;
    if (l != r) {
      tree[k << 1].lazy = (tree[k << 1].lazy * tree[k].lazy) % base;
      tree[k << 1 | 1].lazy = (tree[k << 1 | 1].lazy * tree[k].lazy) % base;
    }
    tree[k].lazy = 1;
  }
  inline void merge_tree(int k) {
    tree[k].sum = (tree[k << 1].sum + tree[k << 1 | 1].sum) % base;
  }

 public:
  void init(int k, int l, int r) {
    if (l > r) return;
    tree[k].sum = 0, tree[k].lazy = tree[k].mul = 1;
    if (l == r) return;
    int mid = (l + r) >> 1;
    init(k << 1, l, mid);
    init(k << 1 | 1, mid + 1, r);
  }
  void updateMul(int k, int l, int r, int L, int R, long long val) {
    lazy_update(k, l, r);
    if (l > r || l > R || r < L) return;
    if (L <= l && r <= R) {
      tree[k].lazy = (tree[k].lazy * val) % base;
      lazy_update(k, l, r);
      return;
    }
    int mid = (l + r) >> 1;
    updateMul(k << 1, l, mid, L, R, val);
    updateMul(k << 1 | 1, mid + 1, r, L, R, val);
    merge_tree(k);
  }
  long long queryMul(int k, int l, int r, int p) {
    if (l > r || l > p || r < p) return 0;
    lazy_update(k, l, r);
    if (l == r && l == p) return tree[k].mul;
    int mid = (l + r) >> 1;
    if (p <= mid) return queryMul(k << 1, l, mid, p);
    return queryMul(k << 1 | 1, mid + 1, r, p);
  }
  void updateNode(int k, int l, int r, int p, long long val) {
    lazy_update(k, l, r);
    if (l > r || l > p || r < p) return;
    if (l == r && l == p) {
      tree[k].sum = val % base;
      return;
    }
    int mid = (l + r) >> 1;
    updateNode(k << 1, l, mid, p, val);
    updateNode(k << 1 | 1, mid + 1, r, p, val);
    merge_tree(k);
  }
  long long querySum(int k, int l, int r, int L, int R) {
    if (l > r || l > R || r < L) return 0;
    lazy_update(k, l, r);
    if (L <= l && r <= R) return tree[k].sum;
    int mid = (l + r) >> 1;
    return (querySum(k << 1, l, mid, L, R) +
            querySum(k << 1 | 1, mid + 1, r, L, R)) %
           base;
  }
};
struct Query {
  int type, u, v;
  Query(int _t, int _u, int _v) : type(_t), u(_u), v(_v) {}
};
const int N = (int)2e5 + 5;
int n, m, deg[N], tin[N], tout[N], par[N], timer;
long long a[N];
vector<int> g[N];
vector<Query> q;
SegTree tr;
long long fast_pw(long long x, long long y) {
  if (!y) return 1ll;
  if (y == 1) return x % base;
  long long tmp = fast_pw(x, y / 2ll);
  tmp = (tmp * tmp) % base;
  if (y % 2ll) tmp = (tmp * x) % base;
  return tmp;
}
long long inverse(long long x) { return fast_pw(x, base - 2ll); }
void dfs_prep(int u) {
  tin[u] = ++timer;
  for (int i = (0); i < (((int)g[u].size())); ++i) {
    int v = g[u][i];
    par[v] = u;
    dfs_prep(v);
  }
  tout[u] = timer;
}
int main() {
  scanf("%I64d%d", &a[1], &m);
  n = 1;
  for (int i = (1); i <= (m); ++i) {
    int type, u;
    long long v;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%I64d", &u, &v);
      g[u].push_back(++n);
      a[n] = v, q.push_back(Query(1, u, n));
    } else {
      scanf("%d", &u);
      q.push_back(Query(2, u, 0));
    }
  }
  tr.init(1, 1, n);
  dfs_prep(1);
  tr.updateNode(1, 1, n, tin[1], a[1]);
  for (int i = (0); i < (m); ++i) {
    if (q[i].type == 1) {
      long long val =
          ((long long)(deg[q[i].u] + 2) * inverse(deg[q[i].u] + 1)) % base;
      tr.updateMul(1, 1, n, tin[q[i].u], tout[q[i].u], val);
      ++deg[q[i].u];
      long long tmp = (tr.queryMul(1, 1, n, tin[q[i].u]) * a[q[i].v]) % base;
      tr.updateNode(1, 1, n, tin[q[i].v], tmp);
    } else {
      long long tmp =
          (!par[q[i].u] ? 1 : inverse(tr.queryMul(1, 1, n, tin[par[q[i].u]])));
      long long ans =
          (tr.querySum(1, 1, n, tin[q[i].u], tout[q[i].u]) * tmp) % base;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}