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;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
int gcd(int x, int y) {
  while (y) {
    int t = x % y;
    x = y;
    y = t;
  }
  return x;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
namespace FastIO {
bool IOError = 0;
inline char NextChar() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOError = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool Blank(char c) {
  return c == ' ' || c == '\n' || c == '\r' || c == '\t';
}
inline void read(int &x) {
  bool sign = 0;
  char ch = NextChar();
  x = 0;
  for (; Blank(ch); ch = NextChar())
    ;
  if (IOError) return;
  if (ch == '-') sign = 1, ch = NextChar();
  for (; ch >= '0' && ch <= '9'; ch = NextChar()) x = x * 10 + ch - '0';
  if (sign) x = -x;
}
inline void read(long long &x) {
  bool sign = 0;
  char ch = NextChar();
  x = 0;
  for (; Blank(ch); ch = NextChar())
    ;
  if (IOError) return;
  if (ch == '-') sign = 1, ch = NextChar();
  for (; ch >= '0' && ch <= '9'; ch = NextChar()) x = x * 10 + ch - '0';
  if (sign) x = -x;
}
inline void read(double &x) {
  bool sign = 0;
  char ch = NextChar();
  x = 0;
  for (; Blank(ch); ch = NextChar())
    ;
  if (IOError) return;
  if (ch == '-') sign = 1, ch = NextChar();
  for (; ch >= '0' && ch <= '9'; ch = NextChar()) x = x * 10 + ch - '0';
  if (ch == '.') {
    double tmp = 1;
    ch = NextChar();
    for (; ch >= '0' && ch <= '9'; ch = NextChar())
      tmp /= 10.0, x += tmp * (ch - '0');
  }
  if (sign) x = -x;
}
inline void read(char *s) {
  char ch = NextChar();
  for (; Blank(ch); ch = NextChar())
    ;
  if (IOError) return;
  for (; !Blank(ch) && !IOError; ch = NextChar()) *s++ = ch;
  *s = 0;
}
inline void read(char &c) {
  for (c = NextChar(); Blank(c); c = NextChar())
    ;
  if (IOError) {
    c = -1;
    return;
  }
}
}  // namespace FastIO
using namespace FastIO;
vector<int> g[300100];
int inv[300100], deg[300100], n, q, a[300100], fa[300100], tot, st[300100],
    ed[300100];
int typ[300100], id[300100], sum[300100 << 2], tag[300100 << 2];
void dfs(int u) {
  st[u] = ++tot;
  for (auto v : g[u]) dfs(v);
  ed[u] = tot;
}
int mod_inv(int x) {
  return x <= n ? inv[x]
                : 1000000007 - (int)(1000000007 / x * 1LL *
                                     mod_inv(1000000007 % x) % 1000000007);
}
void up(int rt) {
  sum[rt] = sum[(rt << 1)] + sum[((rt << 1) | 1)];
  if (sum[rt] >= 1000000007) sum[rt] -= 1000000007;
}
void pd(int rt) {
  if (tag[rt] > 1) {
    sum[(rt << 1)] = 1LL * sum[(rt << 1)] * tag[rt] % 1000000007;
    tag[(rt << 1)] = 1LL * tag[(rt << 1)] * tag[rt] % 1000000007;
    sum[((rt << 1) | 1)] = 1LL * sum[((rt << 1) | 1)] * tag[rt] % 1000000007;
    tag[((rt << 1) | 1)] = 1LL * tag[((rt << 1) | 1)] * tag[rt] % 1000000007;
    tag[rt] = 1;
  }
}
void build(int rt, int ll, int rr) {
  sum[rt] = 0, tag[rt] = 1;
  if (ll == rr) return;
  build((rt << 1), ll, ((ll + rr) / 2));
  build(((rt << 1) | 1), ((ll + rr) / 2) + 1, rr);
}
void change(int rt, int ll, int rr, int x, int v) {
  if (ll == rr) {
    sum[rt] = v;
    return;
  }
  pd(rt);
  if (x <= ((ll + rr) / 2))
    change((rt << 1), ll, ((ll + rr) / 2), x, v);
  else
    change(((rt << 1) | 1), ((ll + rr) / 2) + 1, rr, x, v);
  up(rt);
}
void mul(int rt, int ll, int rr, int l, int r, int v) {
  if (l <= ll && r >= rr) {
    sum[rt] = 1LL * sum[rt] * v % 1000000007;
    tag[rt] = 1LL * tag[rt] * v % 1000000007;
    return;
  }
  pd(rt);
  if (l <= ((ll + rr) / 2)) mul((rt << 1), ll, ((ll + rr) / 2), l, r, v);
  if (r > ((ll + rr) / 2))
    mul(((rt << 1) | 1), ((ll + rr) / 2) + 1, rr, l, r, v);
  up(rt);
}
int query(int rt, int ll, int rr, int l, int r) {
  if (l <= ll && r >= rr) return sum[rt];
  pd(rt);
  int res = 0;
  if (l <= ((ll + rr) / 2)) {
    res += query((rt << 1), ll, ((ll + rr) / 2), l, r);
    if (res >= 1000000007) res -= 1000000007;
  }
  if (r > ((ll + rr) / 2)) {
    res += query(((rt << 1) | 1), ((ll + rr) / 2) + 1, rr, l, r);
    if (res >= 1000000007) res -= 1000000007;
  }
  up(rt);
  return res;
}
int main() {
  n = 0;
  read(a[++n]);
  read(q);
  for (int i = 0; i < q; i++) {
    read(typ[i]);
    if (typ[i] == 1) {
      id[i] = ++n;
      read(fa[n]);
      read(a[n]);
      g[fa[n]].push_back(n);
    } else {
      read(id[i]);
    }
  }
  inv[1] = 1;
  for (int i = 2; i <= n; i++)
    inv[i] = 1000000007 -
             (int)(1000000007 / i * 1LL * inv[1000000007 % i] % 1000000007);
  tot = 0;
  dfs(1);
  build(1, 1, n);
  deg[1] = 1;
  change(1, 1, n, 1, a[1]);
  for (int i = 0; i < q; i++) {
    if (typ[i] == 1) {
      int u = id[i], f = fa[u];
      mul(1, 1, n, st[f], st[u] - 1,
          1LL * inv[deg[f]] * (++deg[f]) % 1000000007);
      deg[u] = 1;
      change(1, 1, n, st[u],
             1LL * query(1, 1, n, st[f], st[f]) * mod_inv(a[f]) % 1000000007 *
                 a[u] % 1000000007);
    } else {
      int u = id[i];
      int ans = query(1, 1, n, st[u], ed[u]);
      if (fa[u])
        ans = 1LL * ans * mod_inv(query(1, 1, n, st[fa[u]], st[fa[u]])) %
              1000000007 * a[fa[u]] % 1000000007;
      printf("%d\n", ans);
    }
  }
  return 0;
}