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;
const int INF = 1e9;
const long long INF_LL = 4e18;
const double pi = acos(-1.0);
template <class T>
T& smin(T& x, const T& y) {
  if (x > y) x = y;
  return x;
}
template <class T>
T& smax(T& x, const T& y) {
  if (x < y) x = y;
  return x;
}
template <class T>
T sqr(const T& x) {
  return x * x;
}
template <typename Iterator>
void print(const char* fmt, Iterator begin, Iterator end,
           const char* delimiter = " ", const char* closing = "\n") {
  for (; begin != end; ++begin != end ? printf("%s", delimiter) : 0)
    printf(fmt, *begin);
  printf("%s", closing);
}
const int mod = 1e9 + 7;
void inc(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int add(int x, int y) {
  inc(x, y);
  return x;
}
int mul(int x, int y) { return (long long)x * y % mod; }
void dec(int& x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
int sub(int x, int y) {
  dec(x, y);
  return x;
}
template <class T>
T qpow(T x, long long power) {
  T res = 1;
  for (; power; power >>= 1, x = mul(x, x))
    if (power & 1) res = mul(res, x);
  return res;
}
template <class T>
T inv(T x) {
  return qpow(x, mod - 2);
}
template <class T>
T inverse(const T& x, const T& module) {
  return x < 2 ? x : module - inverse(module % x, x) * module / x;
}
template <class T, class M = T>
class SegmentTreeR {
 public:
  int n, height;
  vector<T> tree;
  vector<M> delta;
  void calc(int i, int k) {
    tree[i] = combine(tree[i << 1], tree[i << 1 | 1]);
    if (delta[i]) tree[i].add(delta[i], k);
  }
  void apply(int i, const M& value, int k) {
    tree[i].add(value, k);
    delta[i].add(value, k);
  }

 public:
  SegmentTreeR(int newn = 0) { init(newn); }
  void init(int newn) {
    n = newn;
    height = sizeof(n) * 8 - __builtin_clz(n);
    vector<T>(2 * n).swap(tree);
    vector<M>(2 * n, M(false)).swap(delta);
  }
  int size() const { return n; }
  T& operator[](int i) { return tree[i + n]; }
  const T& operator[](int i) const { return tree[i + n]; }
  T& f(int i) { return delta[i + n]; }
  void build(int l, int r) {
    int k = 2;
    for (l += n, r += n - 1; r >>= 1, l >>= 1; k <<= 1)
      for (int i = r; i >= l; --i) calc(i, k);
  }
  void build() { build(0, n); }
  void push(int l, int r) {
    int h = height, k = 1 << (h - 1);
    for (l += n, r += n - 1; h; --h, k >>= 1)
      for (int i = l >> h; i <= r >> h; ++i)
        if (delta[i]) {
          apply(i << 1, delta[i], k);
          apply(i << 1 | 1, delta[i], k);
          delta[i] = M(false);
        }
  }
  void push() { push(0, n); }
  void modify(int l, int r, const M& value) {
    if (!value) return;
    push(l, l + 1);
    push(r - 1, r);
    bool cl = false, cr = false;
    int k = 1;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1, k <<= 1) {
      if (cl) calc(l - 1, k);
      if (l & 1) apply(l++, value, k), cl = true;
      if (cr) calc(r, k);
      if (r & 1) apply(--r, value, k), cr = true;
    }
    for (--l; r; l >>= 1, r >>= 1, k <<= 1) {
      if (cl) calc(l, k);
      if (cr && (!cl || l != r)) calc(r, k);
    }
  }
  T query(int l, int r) {
    push(l, l + 1);
    push(r - 1, r);
    T resl = T(), resr = T();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = combine(resl, tree[l++]);
      if (r & 1) resr = combine(tree[--r], resr);
    }
    return combine(resl, resr);
  }
};
struct S {
  int v;
  S(int v = 0) : v(v) {}
  operator int() const { return v; }
  explicit S(bool) : v(1) {}
  explicit operator bool() const { return v != -1; }
  void add(const S& other, int k = 1) { v = mul(v, other.v); }
  friend S combine(const S& lhs, const S& rhs) { return ::add(lhs.v, rhs.v); }
};
const int N = 2e5 + 5;
int q, n;
int p[N], v[N];
int o[N], u[N];
vector<int> g[N];
int tin[N], tout[N], ttime = 0;
void dfs(int v) {
  tin[v] = ttime++;
  for (int u : g[v]) dfs(u);
  tout[v] = ttime;
}
int k[N];
SegmentTreeR<S> tree;
int main() {
  cin.tie(NULL);
  scanf("%d%d", v + 0, &q);
  p[0] = -1;
  n = 1;
  for (int i(0), _b(q); i < _b; ++i) {
    scanf("%d", o + i);
    if (o[i] == 1) {
      scanf("%d%d", p + n, v + n);
      --p[n];
      g[p[n]].push_back(n);
      ++n;
    } else {
      scanf("%d", u + i);
      --u[i];
    }
  }
  dfs(0);
  tree.init(n);
  tree[0] = v[0];
  tree.build();
  memset(k, 0, sizeof k);
  int n0 = n;
  n = 1;
  for (int i(0), _b(q); i < _b; ++i) {
    if (o[i] == 1) {
      tree.push(tin[n], tin[n] + 1);
      tree[tin[n]] = mul(v[n], tree.f(tin[n]));
      tree.build(tin[n], tin[n] + 1);
      int x = p[n];
      ++k[x];
      int d = mul(k[x] + 1, inv(k[x]));
      tree.modify(tin[x], tout[x], d);
      ++n;
    } else {
      int x = u[i];
      int ans = tree.query(tin[x], tout[x]);
      int d = 1;
      if (x != 0) {
        tree.push(tin[p[x]], tin[p[x]] + 1);
        d = inv(tree.f(tin[p[x]]));
      }
      printf("%d\n", mul(ans, d));
    }
  }
  return 0;
}