#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = 1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  bool first = true;
  os << "[";
  for (auto i : v) {
    if (!first) os << ", ";
    os << i;
    first = false;
  }
  return os << "]";
}
const long long N = 3 * 1e5 + 10;
std::vector<long long> v[N];
long long st[N], en[N], timer = 0, n, height[N];
void dfs(long long s, long long lvl) {
  height[s] = lvl;
  st[s] = ++timer;
  for (auto it : v[s]) dfs(it, lvl + 1);
  en[s] = timer;
}
struct S {
  long long sum1 = 0, sum_k = 0;
} seg[4 * N];
void update(long long node, long long l, long long r, long long ql,
            long long qr, long long x, long long k, long long ver) {
  if (l > r or qr < l or r < ql) return;
  if (l >= ql and r <= qr) {
    long long tt = seg[node].sum1;
    (seg[node].sum1 += x) %= mod;
    (seg[node].sum1 += (k * height[ver]) % mod) %= mod;
    (seg[node].sum_k += k) %= mod;
    return;
  }
  long long mid = (l + r) >> 1;
  update(2 * node, l, mid, ql, qr, x, k, ver);
  update(2 * node + 1, mid + 1, r, ql, qr, x, k, ver);
}
long long ans = 0;
void query(long long node, long long l, long long r, long long pos,
           long long ver) {
  if (l > r) return;
  ans += seg[node].sum1;
  ans %= mod;
  ans -= (height[ver] * seg[node].sum_k) % mod;
  ans += mod;
  ans %= mod;
  if (l == r) {
    return;
  }
  long long mid = (l + r) >> 1;
  if (pos <= mid) {
    query(2 * node, l, mid, pos, ver);
  } else {
    query(2 * node + 1, mid + 1, r, pos, ver);
  }
}
long long ft1[N], ft2[N];
long long query(long long* ft, long long b) {
  long long sum = 0;
  for (; b; b -= (b & (-b))) {
    sum += ft[b];
    sum %= mod;
  }
  return sum;
}
void update(long long* ft, long long k, long long v) {
  for (; k <= n; k += (k & (-k))) {
    ft[k] += v;
    ft[k] %= mod;
  }
}
void range_update(long long* ft, long long i, long long j, long long v) {
  update(ft, i, v);
  update(ft, j + 1, -v);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 2; i <= n; ++i) {
    long long par;
    cin >> par;
    v[par].push_back(i);
  }
  dfs(1, 0);
  long long q;
  cin >> q;
  while (q--) {
    long long tt;
    cin >> tt;
    if (tt == 1) {
      long long v, x, k;
      cin >> v >> x >> k;
      long long vals = (x + (k * height[v]) % mod) % mod;
      range_update(ft1, st[v], en[v], vals);
      range_update(ft2, st[v], en[v], k);
    } else {
      long long v;
      cin >> v;
      ans = 0;
      long long tt = query(ft1, st[v]);
      long long tt2 = query(ft2, st[v]);
      tt2 = (height[v] * tt2) % mod;
      tt = (tt - tt2) % mod;
      tt = (tt + mod) % mod;
      cout << tt << '\n';
    }
  }
  return 0;
}

### Prompt

Please formulate a CPP solution to the following problem:

You are given a rooted tree consisting of n vertices numbered from 1 to n. The root of the tree is a vertex number 1.

Initially all vertices contain number 0. Then come q queries, each query has one of the two types:

  * The format of the query: 1 v x k. In response to the query, you need to add to the number at vertex v number x; to the numbers at the descendants of vertex v at distance 1, add x - k; and so on, to the numbers written in the descendants of vertex v at distance i, you need to add x - (i·k). The distance between two vertices is the number of edges in the shortest path between these vertices. 
  * The format of the query: 2 v. In reply to the query you should print the number written in vertex v modulo 1000000007 (109 + 7). 



Process the queries given in the input.

Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of vertices in the tree. The second line contains n - 1 integers p2, p3, ... pn (1 ≤ pi < i), where pi is the number of the vertex that is the parent of vertex i in the tree.

The third line contains integer q (1 ≤ q ≤ 3·105) — the number of queries. Next q lines contain the queries, one per line. The first number in the line is type. It represents the type of the query. If type = 1, then next follow space-separated integers v, x, k (1 ≤ v ≤ n; 0 ≤ x < 109 + 7; 0 ≤ k < 109 + 7). If type = 2, then next follows integer v (1 ≤ v ≤ n) — the vertex where you need to find the value of the number.

Output

For each query of the second type print on a single line the number written in the vertex from the query. Print the number modulo 1000000007 (109 + 7).

Examples

Input

3
1 1
3
1 1 2 1
2 1
2 2


Output

2
1

Note

You can read about a rooted tree here: http://en.wikipedia.org/wiki/Tree_(graph_theory).

### Response

```cpp
#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = 1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  bool first = true;
  os << "[";
  for (auto i : v) {
    if (!first) os << ", ";
    os << i;
    first = false;
  }
  return os << "]";
}
const long long N = 3 * 1e5 + 10;
std::vector<long long> v[N];
long long st[N], en[N], timer = 0, n, height[N];
void dfs(long long s, long long lvl) {
  height[s] = lvl;
  st[s] = ++timer;
  for (auto it : v[s]) dfs(it, lvl + 1);
  en[s] = timer;
}
struct S {
  long long sum1 = 0, sum_k = 0;
} seg[4 * N];
void update(long long node, long long l, long long r, long long ql,
            long long qr, long long x, long long k, long long ver) {
  if (l > r or qr < l or r < ql) return;
  if (l >= ql and r <= qr) {
    long long tt = seg[node].sum1;
    (seg[node].sum1 += x) %= mod;
    (seg[node].sum1 += (k * height[ver]) % mod) %= mod;
    (seg[node].sum_k += k) %= mod;
    return;
  }
  long long mid = (l + r) >> 1;
  update(2 * node, l, mid, ql, qr, x, k, ver);
  update(2 * node + 1, mid + 1, r, ql, qr, x, k, ver);
}
long long ans = 0;
void query(long long node, long long l, long long r, long long pos,
           long long ver) {
  if (l > r) return;
  ans += seg[node].sum1;
  ans %= mod;
  ans -= (height[ver] * seg[node].sum_k) % mod;
  ans += mod;
  ans %= mod;
  if (l == r) {
    return;
  }
  long long mid = (l + r) >> 1;
  if (pos <= mid) {
    query(2 * node, l, mid, pos, ver);
  } else {
    query(2 * node + 1, mid + 1, r, pos, ver);
  }
}
long long ft1[N], ft2[N];
long long query(long long* ft, long long b) {
  long long sum = 0;
  for (; b; b -= (b & (-b))) {
    sum += ft[b];
    sum %= mod;
  }
  return sum;
}
void update(long long* ft, long long k, long long v) {
  for (; k <= n; k += (k & (-k))) {
    ft[k] += v;
    ft[k] %= mod;
  }
}
void range_update(long long* ft, long long i, long long j, long long v) {
  update(ft, i, v);
  update(ft, j + 1, -v);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 2; i <= n; ++i) {
    long long par;
    cin >> par;
    v[par].push_back(i);
  }
  dfs(1, 0);
  long long q;
  cin >> q;
  while (q--) {
    long long tt;
    cin >> tt;
    if (tt == 1) {
      long long v, x, k;
      cin >> v >> x >> k;
      long long vals = (x + (k * height[v]) % mod) % mod;
      range_update(ft1, st[v], en[v], vals);
      range_update(ft2, st[v], en[v], k);
    } else {
      long long v;
      cin >> v;
      ans = 0;
      long long tt = query(ft1, st[v]);
      long long tt2 = query(ft2, st[v]);
      tt2 = (height[v] * tt2) % mod;
      tt = (tt - tt2) % mod;
      tt = (tt + mod) % mod;
      cout << tt << '\n';
    }
  }
  return 0;
}

```