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 <class T>
inline void upmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void upmin(T &a, T b) {
  if (a > b) a = b;
}
const int maxn = 200007;
const int maxm = 200007;
const int maxs = maxn * 5;
const int mod = 1000000007;
const int inf = 0x7fffffff;
const double eps = 1e-7;
typedef int arr[maxn];
typedef int adj[maxm];
typedef int seg[maxs];
inline int fcmp(double a, double b) {
  if (fabs(a - b) <= eps) return 0;
  if (a < b - eps) return -1;
  return 1;
}
inline int add(int a, int b) { return ((long long)a + b) % mod; }
inline int mul(int a, int b) { return ((long long)a * b) % mod; }
inline int dec(int a, int b) { return add(a, mod - b % mod); }
inline int Pow(int a, int b) {
  int t = 1;
  while (b) {
    if (b & 1) t = mul(t, a);
    a = mul(a, a), b >>= 1;
  }
  return t;
}
template <typename Type>
inline Type RD() {
  char c = getchar();
  Type x = 0, flag = 1;
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    flag = -1;
  else
    x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  return x * flag;
}
inline char rdch() {
  char c = getchar();
  while (!isalpha(c)) c = getchar();
  return c;
}
namespace IO {
const int BUF = 20000000;
char Buf[BUF], *buf = Buf, *buff = Buf, _s[4];
void init() { fread(Buf, 1, BUF, stdin); }
void end() { fwrite(Buf, 1, buff - Buf, stdout); }
inline void read(int &a) {
  for (a = 0; *buf < 48; buf++)
    ;
  while (*buf > 47) a = a * 10 + *buf++ - 48;
}
inline void rdch(char &a) {
  for (a = 0; *buf < 'A'; buf++)
    ;
  a = *buf++;
}
inline void write(int a, char b) {
  if (!a)
    *buff++ = '0';
  else {
    char *s = _s;
    for (; a; a /= 10) *s++ = a % 10 + '0';
    while (s-- != _s) *buff++ = *s;
  }
  *buff++ = b;
}
}  // namespace IO
vector<int> G[maxn];
arr fa, deg;
inline void ins(int u, int v) { G[u].push_back(v), deg[u]++, fa[v] = u; }
arr a, inv;
int q, tot;
struct Que {
  int cmd, u, v;
};
Que que[maxn];
void input() {
  IO::read(a[1]), IO::read(q), tot = 1, deg[1] = 1;
  for (int i = 1, _ = q; i <= _; i++) {
    IO::read(que[i].cmd);
    if (que[i].cmd == 1) {
      deg[++tot] = 1;
      IO::read(que[i].u), IO::read(a[tot]);
      ins(que[i].u, tot), que[i].v = tot;
    } else
      IO::read(que[i].u);
  }
  inv[1] = 1;
  for (int i = 2, _ = q; i <= _; i++)
    inv[i] = dec(0, mul(mod / i, inv[mod % i]));
}
arr cnt, idx;
struct SegTree {
  seg val, tg;
  int ql, qr, v;
  void B(int flag, int u = 1, int l = 1, int r = tot) {
    tg[u] = 1;
    if (l == r) return (void)(val[u] = mul(flag ? a[idx[l]] : 1, cnt[idx[l]]));
    int m = (l + r) >> 1;
    B(flag, (u << 1), l, m), B(flag, (u << 1 | 1), m + 1, r);
    val[u] = add(val[(u << 1)], val[(u << 1 | 1)]);
  }
  inline void tag(int u, int v) {
    val[u] = mul(val[u], v);
    tg[u] = mul(tg[u], v);
  }
  inline void push(int u) {
    if (tg[u] == 1) return;
    tag((u << 1), tg[u]), tag((u << 1 | 1), tg[u]);
    tg[u] = 1;
  }
  void modi(int u = 1, int l = 1, int r = tot) {
    if (ql <= l && r <= qr) return (void)(tag(u, v));
    push(u);
    int m = (l + r) >> 1;
    if (ql <= m) modi((u << 1), l, m);
    if (qr > m) modi((u << 1 | 1), m + 1, r);
    val[u] = add(val[(u << 1)], val[(u << 1 | 1)]);
  }
  inline void M(int l, int r, int v) {
    if (l > r) return;
    ql = l, qr = r, this->v = v;
    modi();
  }
  int que(int u = 1, int l = 1, int r = tot) {
    if (ql <= l && r <= qr) return val[u];
    push(u);
    int m = (l + r) >> 1, t = 0;
    if (ql <= m) t = que((u << 1), l, m);
    if (qr > m) t = add(t, que((u << 1 | 1), m + 1, r));
    return t;
  }
  inline int Q(int l, int r) {
    if (!l) return 1;
    assert(l <= r);
    ql = l, qr = r;
    return que();
  }
} tr1, tr2;
arr st, ed;
void dfs(int u) {
  static int dfs_clock;
  st[u] = ++dfs_clock;
  idx[dfs_clock] = u;
  for (int v : G[u]) cnt[v] = mul(cnt[u], deg[v]), dfs(v);
  ed[u] = dfs_clock;
}
void solve() {
  cnt[1] = deg[1], dfs(1);
  tr1.B(1), tr2.B(0);
  static arr ans;
  for (int i = q, _ = 1; i >= _; i--)
    if (que[i].cmd == 1) {
      int u = que[i].v, p = que[i].u;
      int v = mul(deg[p] - 1, Pow(deg[p], mod - 2));
      tr1.M(st[p], ed[p], v);
      tr1.M(st[u], st[u], 0);
      tr2.M(st[p], ed[p], v);
      tr2.M(st[u], st[u], 0);
      deg[p]--;
    } else {
      int u = que[i].u;
      int v1 = tr1.Q(st[u], ed[u]), v2 = tr2.Q(st[fa[u]], st[fa[u]]);
      ans[i] = mul(v1, Pow(v2, mod - 2));
    }
  for (int i = 1, _ = q; i <= _; i++)
    if (que[i].cmd == 2) printf("%d\n", ans[i]);
}
int main() {
  IO::init();
  input();
  solve();
  return 0;
}