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>
const int N = 3e5 + 10;
const int mod = 1e9 + 7;
int n;
std::vector<int> edge[N];
std::pair<int, int> v[N];
int q;
std::pair<int, int> query[N];
int queue[N];
std::pair<int, int> range[N];
int father[N];
int degree[N];
int fastPower(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) {
      ret = (long long)ret * x % mod;
    }
    x = (long long)x * x % mod;
  }
  return ret;
}
int inv(int x) { return fastPower(x, mod - 2); }
int lowbit(int x) { return x & (-x); }
struct FenwickTree {
  int e[N];
  void build(int size) {
    for (int i = 1; i <= size; i++) {
      e[i] = 1;
    }
  }
  void change(int x, int value) {
    for (int i = x; i <= n; i += lowbit(i)) {
      e[i] = (long long)e[i] * value % mod;
    }
  }
  int getValue(int x) {
    int ret = 1;
    for (int i = x; i >= 1; i -= lowbit(i)) {
      ret = (long long)ret * e[i] % mod;
    }
    return ret;
  }
};
FenwickTree ft;
struct SegmentTree {
  struct Node {
    int sum;
    int tag;
  };
  Node tree[N << 2];
  void update(int root, int left, int right) {
    tree[root].sum = (long long)tree[root].sum * tree[root].tag % mod;
    if (left != right) {
      tree[root << 1].tag =
          (long long)tree[root << 1].tag * tree[root].tag % mod;
      tree[root << 1 | 1].tag =
          (long long)tree[root << 1 | 1].tag * tree[root].tag % mod;
    }
    tree[root].tag = 1;
  }
  void change(int root, int left, int right, int pos, int value) {
    update(root, left, right);
    if (left == pos && right == pos) {
      tree[root].sum = value;
      return;
    }
    int mid = (left + right) >> 1;
    if (pos <= mid) {
      change(root << 1, left, mid, pos, value);
    } else {
      change(root << 1 | 1, mid + 1, right, pos, value);
    }
    update(root << 1, left, mid);
    update(root << 1 | 1, mid + 1, right);
    tree[root].sum = tree[root << 1].sum + tree[root << 1 | 1].sum;
  }
  void change2(int root, int left, int right, int ql, int qr, int value) {
    update(root, left, right);
    if (left == ql && right == qr) {
      tree[root].tag = value;
      update(root, left, right);
      return;
    }
    int mid = (left + right) >> 1;
    if (qr <= mid) {
      change2(root << 1, left, mid, ql, qr, value);
    } else if (ql > mid) {
      change2(root << 1 | 1, mid + 1, right, ql, qr, value);
    } else {
      change2(root << 1, left, mid, ql, mid, value);
      change2(root << 1 | 1, mid + 1, right, mid + 1, qr, value);
    }
    update(root << 1, left, mid);
    update(root << 1 | 1, mid + 1, right);
    tree[root].sum = tree[root << 1].sum + tree[root << 1 | 1].sum;
  }
  int getSum(int root, int left, int right, int ql, int qr) {
    update(root, left, right);
    if (left == ql && right == qr) {
      return tree[root].sum;
    }
    int mid = (left + right) >> 1;
    if (qr <= mid) {
      return getSum(root << 1, left, mid, ql, qr);
    } else if (ql > mid) {
      return getSum(root << 1 | 1, mid + 1, right, ql, qr);
    } else {
      return (getSum(root << 1, left, mid, ql, mid) +
              getSum(root << 1 | 1, mid + 1, right, mid + 1, qr)) %
             mod;
    }
  }
};
SegmentTree st;
void init() {
  std::cin >> v[1].second >> q;
  n = 1;
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &query[i].first, &query[i].second);
    if (query[i].first == 1) {
      father[++n] = query[i].second;
      scanf("%d", &v[n].second);
      edge[father[n]].push_back(n);
    }
  }
}
void dfs(int u) {
  static int tot = 0;
  queue[++tot] = u;
  range[u].first = tot;
  for (int i = 0; i < (int)edge[u].size(); i++) {
    dfs(edge[u][i]);
  }
  range[u].second = tot;
}
void work() {
  dfs(1);
  std::fill(degree + 1, degree + n + 1, 1);
  ft.build(n);
  int tmp = 1;
  v[1].first = v[1].second;
  st.change(1, 1, n, range[1].first, v[1].first);
  for (int i = 1; i <= q; i++) {
    if (query[i].first == 1) {
      int fa = query[i].second;
      tmp++;
      v[tmp].first = v[tmp].second;
      degree[fa]++;
      int cc = (long long)degree[fa] * inv(degree[fa] - 1) % mod;
      ft.change(range[fa].first, cc);
      ft.change(range[fa].second + 1, inv(cc));
      st.change2(1, 1, n, range[fa].first, range[fa].second, cc);
      st.change(1, 1, n, range[tmp].first,
                (long long)v[tmp].first * ft.getValue(range[tmp].first) % mod);
    } else {
      int u = query[i].second;
      int answer = st.getSum(1, 1, n, range[u].first, range[u].second);
      if (u != 1) {
        answer =
            (long long)answer * inv(ft.getValue(range[father[u]].first)) % mod;
      }
      printf("%d\n", answer);
    }
  }
}
int main() {
  init();
  work();
  return 0;
}