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("Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAXBUF = 1 << 23;
char B[MAXBUF], *Si = B, *Ti = B;
inline char getc() {
  if (Si == Ti) Ti = (Si = B) + fread(B, 1, MAXBUF, stdin);
  if (Si == Ti)
    return 0;
  else
    return *Si++;
}
template <class T>
inline void read(T &a) {
  static char c;
  static int fh;
  while (((c = getc()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    fh = -1, a = 0;
  else
    fh = 1, a = c - '0';
  while ((c = getc()) <= '9' && c >= '0') a = (a << 3) + (a << 1) + c - '0';
  if (fh == -1) a = -a;
}
char Buff[MAXBUF], *sti = Buff;
template <class T>
inline void write(T a) {
  if (a == 0) {
    *sti++ = '0';
    return;
  }
  if (a < 0) *sti++ = '-', a = -a;
  static char c[20];
  static int c0;
  c0 = 0;
  while (a) c[c0++] = a % 10 + '0', a /= 10;
  while (c0--) *sti++ = c[c0];
}
int head[200005], nxt[200005], v[200005], tot = 0;
int a[200005], l[200005], r[200005], cnt = 1, num = 0;
int opt[200005], x[200005], dfn[200005], deg[200005];
int fa[200005];
inline int qpow(int a, int b) {
  int res = 1, tp = a;
  while (b) {
    if (b & 1) res = 1ll * res * tp % 1000000007;
    tp = 1ll * tp * tp % 1000000007;
    b >>= 1;
  }
  return res;
}
inline void add(int a, int b) {
  tot++;
  nxt[tot] = head[a];
  head[a] = tot;
  v[tot] = b;
}
struct seg_tree {
  int tag[600005], s[600005];
  void build(int pos, int l, int r) {
    tag[pos] = 1;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build((pos << 1), l, mid);
    build((pos << 1 | 1), mid + 1, r);
    s[pos] = s[(pos << 1)] + s[(pos << 1 | 1)];
    if (s[pos] >= 1000000007) s[pos] -= 1000000007;
  }
  inline void tagdown(int pos) {
    if (tag[(pos << 1)] ^ 1) {
      tag[(pos << 1)] = 1ll * tag[(pos << 1)] * tag[pos] % 1000000007;
    } else {
      tag[(pos << 1)] = tag[pos];
    }
    if (tag[(pos << 1 | 1)] ^ 1) {
      tag[(pos << 1 | 1)] = 1ll * tag[(pos << 1 | 1)] * tag[pos] % 1000000007;
    } else {
      tag[(pos << 1 | 1)] = tag[pos];
    }
    s[(pos << 1)] = 1ll * s[(pos << 1)] * tag[pos] % 1000000007;
    s[(pos << 1 | 1)] = 1ll * s[(pos << 1 | 1)] * tag[pos] % 1000000007;
    tag[pos] = 1;
  }
  inline void add(int pos, int l, int r, int pl, int x) {
    if (l == r) {
      s[pos] = x;
      return;
    }
    tagdown(pos);
    int mid = (l + r) >> 1;
    if (pl <= mid) {
      add((pos << 1), l, mid, pl, x);
    } else {
      add((pos << 1 | 1), mid + 1, r, pl, x);
    }
    s[pos] = s[(pos << 1)] + s[(pos << 1 | 1)];
    if (s[pos] >= 1000000007) s[pos] -= 1000000007;
  }
  void mul(int pos, int l, int r, int lp, int rp, int x) {
    if (l == lp && r == rp) {
      if (tag[pos] ^ 1) {
        tag[pos] = 1ll * tag[pos] * x % 1000000007;
      } else {
        tag[pos] = x;
      }
      s[pos] = 1ll * s[pos] * x % 1000000007;
      return;
    }
    if (tag[pos] ^ 1) tagdown(pos);
    int mid = (l + r) >> 1;
    if (lp > mid) mul((pos << 1 | 1), mid + 1, r, lp, rp, x);
    if (rp <= mid) mul((pos << 1), l, mid, lp, rp, x);
    if (lp <= mid && rp > mid) {
      mul((pos << 1), l, mid, lp, mid, x);
      mul((pos << 1 | 1), mid + 1, r, mid + 1, rp, x);
    }
    s[pos] = s[(pos << 1)] + s[(pos << 1 | 1)];
    if (s[pos] >= 1000000007) s[pos] -= 1000000007;
  }
  int query(int pos, int l, int r, int lp, int rp) {
    if (l == lp && r == rp) return s[pos];
    if (tag[pos] ^ 1) tagdown(pos);
    int mid = (l + r) >> 1;
    if (lp > mid) return query((pos << 1 | 1), mid + 1, r, lp, rp);
    if (rp <= mid) return query((pos << 1), l, mid, lp, rp);
    int res = query((pos << 1), l, mid, lp, mid) +
              query((pos << 1 | 1), mid + 1, r, mid + 1, rp);
    if (res >= 1000000007) res -= 1000000007;
    return res;
  }
} T;
void dfs(int pos) {
  l[pos] = ++num;
  dfn[num] = pos;
  for (int i = head[pos]; i; i = nxt[i]) {
    dfs(v[i]);
  }
  r[pos] = num;
}
int main() {
  int i, q, num = 1;
  read(a[1]);
  read(q);
  for (i = 1; i <= q; i++) {
    read(opt[i]);
    read(x[i]);
    if (opt[i] == 1) {
      read(a[++cnt]);
      fa[cnt] = x[i];
      add(x[i], cnt);
    }
  }
  dfs(1);
  T.build(1, 1, cnt);
  T.add(1, 1, cnt, 1, a[1]);
  for (i = 1; i <= q; i++) {
    if (opt[i] == 1) {
      deg[x[i]]++;
      num++;
      int o =
          1ll * (deg[x[i]] + 1) * qpow(deg[x[i]], 1000000007 - 2) % 1000000007;
      int ovo = 1ll * qpow(a[x[i]], 1000000007 - 2) *
                T.query(1, 1, cnt, l[x[i]], l[x[i]]) % 1000000007;
      T.add(1, 1, cnt, l[num], 1ll * a[num] * ovo % 1000000007);
      T.mul(1, 1, cnt, l[x[i]], r[x[i]], o);
      continue;
    }
    int srt = T.query(1, 1, cnt, l[x[i]], r[x[i]]);
    if (x[i] ^ 1) {
      int ovo =
          1ll * a[fa[x[i]]] *
          qpow(T.query(1, 1, cnt, l[fa[x[i]]], l[fa[x[i]]]), 1000000007 - 2) %
          1000000007;
      srt = 1ll * srt * ovo % 1000000007;
    }
    write(srt), *sti++ = '\n';
  }
  fwrite(Buff, 1, sti - Buff, stdout);
  return 0;
}