#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void add_fenwick(vector<int>* arr, int i, int dy) {
  while (i < arr->size()) {
    (*arr)[i] = ((*arr)[i] + dy) % MOD;
    i |= (i + 1);
  }
}
int sum_fenwick(vector<int>* arr, int n) {
  int sum = 0;
  while (n > 0) {
    sum = (sum + (*arr)[n - 1]) % MOD;
    n &= (n - 1);
  }
  return sum;
}
int index_of(vector<int>* arr, int x) {
  return lower_bound(arr->begin(), arr->end(), x) - arr->begin();
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> parents = vector<int>(n);
  parents[0] = -1;
  for (int u = 1; u < n; u++) {
    cin >> parents[u];
    --parents[u];
  }
  vector<int> sizes = vector<int>(n);
  vector<vector<int> > children = vector<vector<int> >(n);
  for (int u = 0; u < n; u++) {
    sizes[u] = 0;
    children[u] = vector<int>();
  }
  for (int u = n - 1; u >= 0; --u) {
    ++sizes[u];
    reverse(children[u].begin(), children[u].end());
    if (parents[u] >= 0) {
      sizes[parents[u]] += sizes[u];
      children[parents[u]].push_back(u);
    }
  }
  vector<int> levels = vector<int>(n);
  int treeHeight = 0;
  levels[0] = 0;
  for (int u = 1; u < n; u++) {
    levels[u] = levels[parents[u]] + 1;
    treeHeight = max(treeHeight, levels[u]);
  }
  vector<int> heavyChildren = vector<int>(n);
  vector<bool> isHeavyChild = vector<bool>(n);
  for (int u = 0; u < n; u++) isHeavyChild[u] = false;
  for (int u = 0; u < n; u++) {
    heavyChildren[u] = -1;
    for (int v : children[u]) {
      if ((sizes[v] * 2) > (sizes[u] - 1)) {
        heavyChildren[u] = v;
        isHeavyChild[v] = true;
      }
    }
  }
  vector<vector<int>*> hld = vector<vector<int>*>(n);
  vector<vector<int>*> xHld = vector<vector<int>*>(n);
  vector<vector<int>*> kHld = vector<vector<int>*>(n);
  vector<vector<int>*> khHld = vector<vector<int>*>(n);
  for (int u = 0; u < n; u++) {
    if (isHeavyChild[u]) {
      hld[u] = hld[parents[u]];
      xHld[u] = xHld[parents[u]];
      kHld[u] = kHld[parents[u]];
      khHld[u] = khHld[parents[u]];
    } else {
      hld[u] = new vector<int>();
      xHld[u] = new vector<int>();
      kHld[u] = new vector<int>();
      khHld[u] = new vector<int>();
    }
    hld[u]->push_back(u);
    xHld[u]->push_back(0);
    kHld[u]->push_back(0);
    khHld[u]->push_back(0);
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int u, x, k;
      cin >> u >> x >> k;
      --u;
      add_fenwick(xHld[u], index_of(hld[u], u), x);
      add_fenwick(kHld[u], index_of(hld[u], u), k);
      add_fenwick(khHld[u], index_of(hld[u], u),
                  (k * (long long)levels[u]) % MOD);
    } else {
      int u;
      cin >> u;
      --u;
      int u0 = u;
      int sumX = 0;
      int sumK = 0;
      int sumKH = 0;
      while (u >= 0) {
        sumX = (sumX + sum_fenwick(xHld[u], index_of(hld[u], u) + 1)) % MOD;
        sumK = (sumK + sum_fenwick(kHld[u], index_of(hld[u], u) + 1)) % MOD;
        sumKH = (sumKH + sum_fenwick(khHld[u], index_of(hld[u], u) + 1)) % MOD;
        u = parents[hld[u]->at(0)];
      }
      int result =
          (sumX + (long long)sumKH - (sumK * (long long)levels[u0])) % MOD;
      if (result < 0) result += MOD;
      cout << result << endl;
    }
  }
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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 int MOD = 1000000007;
void add_fenwick(vector<int>* arr, int i, int dy) {
  while (i < arr->size()) {
    (*arr)[i] = ((*arr)[i] + dy) % MOD;
    i |= (i + 1);
  }
}
int sum_fenwick(vector<int>* arr, int n) {
  int sum = 0;
  while (n > 0) {
    sum = (sum + (*arr)[n - 1]) % MOD;
    n &= (n - 1);
  }
  return sum;
}
int index_of(vector<int>* arr, int x) {
  return lower_bound(arr->begin(), arr->end(), x) - arr->begin();
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> parents = vector<int>(n);
  parents[0] = -1;
  for (int u = 1; u < n; u++) {
    cin >> parents[u];
    --parents[u];
  }
  vector<int> sizes = vector<int>(n);
  vector<vector<int> > children = vector<vector<int> >(n);
  for (int u = 0; u < n; u++) {
    sizes[u] = 0;
    children[u] = vector<int>();
  }
  for (int u = n - 1; u >= 0; --u) {
    ++sizes[u];
    reverse(children[u].begin(), children[u].end());
    if (parents[u] >= 0) {
      sizes[parents[u]] += sizes[u];
      children[parents[u]].push_back(u);
    }
  }
  vector<int> levels = vector<int>(n);
  int treeHeight = 0;
  levels[0] = 0;
  for (int u = 1; u < n; u++) {
    levels[u] = levels[parents[u]] + 1;
    treeHeight = max(treeHeight, levels[u]);
  }
  vector<int> heavyChildren = vector<int>(n);
  vector<bool> isHeavyChild = vector<bool>(n);
  for (int u = 0; u < n; u++) isHeavyChild[u] = false;
  for (int u = 0; u < n; u++) {
    heavyChildren[u] = -1;
    for (int v : children[u]) {
      if ((sizes[v] * 2) > (sizes[u] - 1)) {
        heavyChildren[u] = v;
        isHeavyChild[v] = true;
      }
    }
  }
  vector<vector<int>*> hld = vector<vector<int>*>(n);
  vector<vector<int>*> xHld = vector<vector<int>*>(n);
  vector<vector<int>*> kHld = vector<vector<int>*>(n);
  vector<vector<int>*> khHld = vector<vector<int>*>(n);
  for (int u = 0; u < n; u++) {
    if (isHeavyChild[u]) {
      hld[u] = hld[parents[u]];
      xHld[u] = xHld[parents[u]];
      kHld[u] = kHld[parents[u]];
      khHld[u] = khHld[parents[u]];
    } else {
      hld[u] = new vector<int>();
      xHld[u] = new vector<int>();
      kHld[u] = new vector<int>();
      khHld[u] = new vector<int>();
    }
    hld[u]->push_back(u);
    xHld[u]->push_back(0);
    kHld[u]->push_back(0);
    khHld[u]->push_back(0);
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int u, x, k;
      cin >> u >> x >> k;
      --u;
      add_fenwick(xHld[u], index_of(hld[u], u), x);
      add_fenwick(kHld[u], index_of(hld[u], u), k);
      add_fenwick(khHld[u], index_of(hld[u], u),
                  (k * (long long)levels[u]) % MOD);
    } else {
      int u;
      cin >> u;
      --u;
      int u0 = u;
      int sumX = 0;
      int sumK = 0;
      int sumKH = 0;
      while (u >= 0) {
        sumX = (sumX + sum_fenwick(xHld[u], index_of(hld[u], u) + 1)) % MOD;
        sumK = (sumK + sum_fenwick(kHld[u], index_of(hld[u], u) + 1)) % MOD;
        sumKH = (sumKH + sum_fenwick(khHld[u], index_of(hld[u], u) + 1)) % MOD;
        u = parents[hld[u]->at(0)];
      }
      int result =
          (sumX + (long long)sumKH - (sumK * (long long)levels[u0])) % MOD;
      if (result < 0) result += MOD;
      cout << result << endl;
    }
  }
  return 0;
}

```