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 <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &_p) {
  return os << "(" << _p.first << "," << _p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &_V) {
  bool f = true;
  os << "[";
  for (auto v : _V) {
    os << (f ? "" : ",") << v;
    f = false;
  }
  return os << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &_S) {
  bool f = true;
  os << "(";
  for (auto s : _S) {
    os << (f ? "" : ",") << s;
    f = false;
  }
  return os << ")";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &_M) {
  return os << set<pair<T, U>>(_M.begin(), _M.end());
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const signed long long INF = 1000000100;
const long double EPS = 1e-9;
const signed long long mod = 1000000007;
struct tree {
  struct node {
    signed long long result;
    signed long long lazy_add;
    signed long long lazy_mult;
    node() : result(0), lazy_add(0), lazy_mult(1) {}
  };
  const signed long long ZERO = 0;
  inline void update(int v, signed long long cmult, signed long long cadd) {
    T[v].lazy_mult *= cmult;
    T[v].lazy_add *= cmult;
    T[v].lazy_add += cadd;
    T[v].lazy_mult %= mod;
    T[v].lazy_add %= mod;
  }
  inline void push(int v) {
    if (v >= M) {
      T[v].result = eval2(v, 1);
      T[v].lazy_mult = 1;
      T[v].lazy_add = 0;
    } else {
      update(2 * v, T[v].lazy_mult, T[v].lazy_add);
      update(2 * v + 1, T[v].lazy_mult, T[v].lazy_add);
      T[v].lazy_mult = 1;
      T[v].lazy_add = 0;
    }
  }
  inline signed long long eval2(int v, int s) {
    signed long long ret = T[v].result * T[v].lazy_mult + T[v].lazy_add * s;
    ret %= mod;
    return ret;
  }
  inline signed long long eval(int v, int s) {
    if (v >= M) {
      return eval2(v, s);
    } else {
      return merge(eval2(2 * v, s / 2), eval2(2 * v + 1, s / 2));
    }
  }
  inline signed long long merge(const signed long long &x,
                                const signed long long &y) {
    return (x + y) % mod;
  }
  int M;
  node *T;
  tree(int n) : M(1 << (32 - __builtin_clz(n))), T(new node[2 * M]) {}
  inline signed long long query(int a, int b, int l, int r, int v) {
    if (a > r or b < l) return ZERO;
    push(v);
    if (a == l and r == b) {
      return T[v].result = eval(v, r - l + 1);
    }
    int mid = (l + r) / 2;
    signed long long x = query(a, min(b, mid), l, mid, 2 * v);
    signed long long y = query(max(a, mid + 1), b, mid + 1, r, 2 * v + 1);
    T[v].result = eval(v, r - l + 1);
    return merge(x, y);
  }
  inline void insert(int a, int b, int l, int r, int v, signed long long cmult,
                     signed long long cadd) {
    if (a > r or b < l) return;
    push(v);
    if (a == l and r == b) {
      update(v, cmult, cadd);
      push(v);
      T[v].result = eval(v, r - l + 1);
      return;
    }
    int mid = (l + r) / 2;
    insert(a, min(b, mid), l, mid, 2 * v, cmult, cadd);
    insert(max(a, mid + 1), b, mid + 1, r, 2 * v + 1, cmult, cadd);
    T[v].result = eval(v, r - l + 1);
  }
  inline signed long long query(int a, int b) {
    return query(a, b, 0, M - 1, 1);
  }
  inline void insert(int a, int b, signed long long cmult,
                     signed long long cadd) {
    insert(a, b, 0, M - 1, 1, cmult, cadd);
  }
};
struct brute {
  vector<signed long long> A;
  brute(int N) : A(N, 0) {}
  void insert(int a, int b, signed long long c, signed long long d) {
    for (int(i) = (a); (i) <= (b); (i)++) A[i] = (A[i] * c + d) % mod;
  }
  signed long long query(int a, int b) {
    signed long long ret = 0;
    for (int(i) = (a); (i) <= (b); (i)++) ret = (ret + A[i]) % mod;
    return ret % mod;
  }
};
void test() {
  srand(time(NULL));
  const int N = 1000;
  const int MAX_DELTA = 1000000000;
  tree T(N);
  brute A(N);
  int cnt = 0;
  while (true) {
    int a = rand() % N;
    int b = rand() % N;
    int c = rand() % MAX_DELTA;
    int d = rand() % MAX_DELTA;
    if (a > b) swap(a, b);
    T.insert(a, b, c, d);
    A.insert(a, b, c, d);
    a = rand() % N;
    b = rand() % N;
    if (a > b) swap(a, b);
    int x = T.query(a, b);
    int y = A.query(a, b);
    if (x != y) {
      printf("Failed after %d queries! %lld %lld\n", cnt, x, y);
      exit(1);
    }
    if (++cnt % 100000 == 0) {
      printf("%d queries successfully done\n", cnt);
    }
  }
}
const int MAXN = 200042;
vector<int> V[MAXN];
int pre[MAXN], out[MAXN];
int parent[MAXN];
int deg[MAXN];
signed long long v[MAXN];
signed long long powm(signed long long a, signed long long b) {
  signed long long ret = 1;
  a %= mod;
  while (b) {
    if (b % 2) ret *= a;
    ret %= mod;
    a *= a;
    a %= mod;
    b /= 2;
  }
  return ret;
}
signed long long divm(signed long long a, signed long long b) {
  return (a * powm(b, mod - 2)) % mod;
}
void dfs(int x, int &cnt) {
  cnt++;
  pre[x] = cnt;
  for (int y : V[x]) {
    dfs(y, cnt);
  }
  out[x] = cnt;
}
void solve() {
  int q;
  cin >> v[1] >> q;
  vector<pair<int, int>> queries(q);
  int n = 1;
  for (int(i) = (0); (i) < (q); (i)++) {
    cin >> queries[i].first >> queries[i].second;
    if (queries[i].first == 1) {
      n++;
      cin >> v[n];
      int y = queries[i].second;
      parent[n] = y;
      queries[i].second = n;
      V[y].push_back(n);
    }
  }
  int cnt = 0;
  dfs(1, cnt);
  for (int(i) = (1); (i) <= (n); (i)++)
    ;
  ;
  tree T(n + 1);
  T.insert(1, 1, 1, v[1]);
  for (pair<int, int> p : queries) {
    int x = p.second;
    if (p.first == 1) {
      int y = parent[x];
      deg[y]++;
      signed long long mult = divm(deg[y] + 1, deg[y]);
      T.insert(pre[y], out[y], mult, 0);
      signed long long yweight = T.query(pre[y], pre[y]);
      signed long long ymult = divm(yweight, v[y]);
      ;
      ;
      T.insert(pre[x], pre[x], 0, (ymult * v[x]) % mod);
    } else {
      signed long long ans = T.query(pre[x], out[x]);
      ;
      ;
      signed long long xweight = T.query(pre[x], pre[x]);
      signed long long xmult = divm(xweight, v[x]);
      signed long long mult = divm(xmult, deg[x] + 1);
      ans = divm(ans, mult);
      cout << ans << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  solve();
}