#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)2e9;
const long long md = 1000000007;
long long dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
long long power(long long a, long long p) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans *= a;
    p /= 2;
    a *= a;
    ans %= md;
    a %= md;
  }
  return ans;
}
long long mdinv(long long a) { return power(a, md - 2); }
const long long N = 3e5 + 10;
long long st[N], fin[N], tim;
long long n;
vector<long long> adj[N], arr, ht;
void dfs(long long i, long long h) {
  st[i] = ++tim;
  arr.push_back(tim);
  ht.push_back(h);
  for (long long v : adj[i]) dfs(v, h + 1);
  fin[i] = ++tim;
}
long long ans[N];
pair<long long, long long> seg[4 * N];
void shift(long long i) {
  seg[i * 2] = {(seg[i * 2].first + seg[i].first) % md,
                (seg[i * 2].second + seg[i].second) % md};
  seg[i * 2 + 1] = {(seg[i * 2 + 1].first + seg[i].first) % md,
                    (seg[i * 2 + 1].second + seg[i].second) % md};
  seg[i] = {0, 0};
}
void upd(long long i, long long l, long long r, long long first,
         long long second, long long A, long long B) {
  if (second < l || r < first) return;
  if (first <= l && r <= second) {
    seg[i] = {seg[i].first + A, seg[i].second + B};
    return;
  }
  shift(i);
  upd(i * 2, l, (l + r) / 2, first, second, A, B);
  upd(i * 2 + 1, (l + r) / 2 + 1, r, first, second, A, B);
}
long long qry(long long i, long long l, long long r, long long first) {
  if (l == r) {
    long long first = seg[i].first, k = seg[i].second;
    return (first - ht[l] * k) % md;
  }
  shift(i);
  if (first <= (l + r) / 2) return qry(i * 2, l, (l + r) / 2, first);
  return qry(i * 2 + 1, (l + r) / 2 + 1, r, first);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long tmp;
  for (long long i = 0; i < (long long)n - 1; i++) {
    cin >> tmp;
    adj[tmp].push_back(i + 2);
  }
  dfs(1, 0);
  long long q;
  cin >> q;
  for (long long qq = 0; qq < (long long)q; qq++) {
    long long mode;
    cin >> mode;
    if (mode == 1) {
      long long v, first, k;
      cin >> v >> first >> k;
      long long l =
          lower_bound((arr).begin(), (arr).end(), st[v]) - arr.begin();
      long long r =
          lower_bound((arr).begin(), (arr).end(), fin[v]) - arr.begin() - 1;
      long long A = first + ht[l] * k;
      long long B = k;
      upd(1, 0, n - 1, l, r, A, B);
    } else {
      long long v;
      cin >> v;
      long long l =
          lower_bound((arr).begin(), (arr).end(), st[v]) - arr.begin();
      long long ans = md + qry(1, 0, n - 1, l);
      ans %= md;
      cout << ans << "\n";
    }
  }
}

### Prompt

Please create a solution in CPP 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>
using namespace std;
const long long inf = (long long)2e9;
const long long md = 1000000007;
long long dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
long long power(long long a, long long p) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans *= a;
    p /= 2;
    a *= a;
    ans %= md;
    a %= md;
  }
  return ans;
}
long long mdinv(long long a) { return power(a, md - 2); }
const long long N = 3e5 + 10;
long long st[N], fin[N], tim;
long long n;
vector<long long> adj[N], arr, ht;
void dfs(long long i, long long h) {
  st[i] = ++tim;
  arr.push_back(tim);
  ht.push_back(h);
  for (long long v : adj[i]) dfs(v, h + 1);
  fin[i] = ++tim;
}
long long ans[N];
pair<long long, long long> seg[4 * N];
void shift(long long i) {
  seg[i * 2] = {(seg[i * 2].first + seg[i].first) % md,
                (seg[i * 2].second + seg[i].second) % md};
  seg[i * 2 + 1] = {(seg[i * 2 + 1].first + seg[i].first) % md,
                    (seg[i * 2 + 1].second + seg[i].second) % md};
  seg[i] = {0, 0};
}
void upd(long long i, long long l, long long r, long long first,
         long long second, long long A, long long B) {
  if (second < l || r < first) return;
  if (first <= l && r <= second) {
    seg[i] = {seg[i].first + A, seg[i].second + B};
    return;
  }
  shift(i);
  upd(i * 2, l, (l + r) / 2, first, second, A, B);
  upd(i * 2 + 1, (l + r) / 2 + 1, r, first, second, A, B);
}
long long qry(long long i, long long l, long long r, long long first) {
  if (l == r) {
    long long first = seg[i].first, k = seg[i].second;
    return (first - ht[l] * k) % md;
  }
  shift(i);
  if (first <= (l + r) / 2) return qry(i * 2, l, (l + r) / 2, first);
  return qry(i * 2 + 1, (l + r) / 2 + 1, r, first);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long tmp;
  for (long long i = 0; i < (long long)n - 1; i++) {
    cin >> tmp;
    adj[tmp].push_back(i + 2);
  }
  dfs(1, 0);
  long long q;
  cin >> q;
  for (long long qq = 0; qq < (long long)q; qq++) {
    long long mode;
    cin >> mode;
    if (mode == 1) {
      long long v, first, k;
      cin >> v >> first >> k;
      long long l =
          lower_bound((arr).begin(), (arr).end(), st[v]) - arr.begin();
      long long r =
          lower_bound((arr).begin(), (arr).end(), fin[v]) - arr.begin() - 1;
      long long A = first + ht[l] * k;
      long long B = k;
      upd(1, 0, n - 1, l, r, A, B);
    } else {
      long long v;
      cin >> v;
      long long l =
          lower_bound((arr).begin(), (arr).end(), st[v]) - arr.begin();
      long long ans = md + qry(1, 0, n - 1, l);
      ans %= md;
      cout << ans << "\n";
    }
  }
}

```