#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T>
T sqr(const T& x) {
  return x * x;
}
template <typename T>
T my_abs(const T& x) {
  return x < 0 ? -x : x;
}
const int INF = (int)1e9;
const long long LINF = (long long)6e18;
const long long INF64 = LINF;
const long long INFLL = LINF;
const long double EPS = 1e-8;
const long double PI = 3.1415926535897932384626433832795;
const long double ME = 1e-5;
const long long MOD = (int)1e9 + 7;
const long long MOD2 = (int)1e9 + 21;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int SQN = 5000;
const int LOGN = 17;
const int N = (int)6e5 + 10;
const int M = (int)1e5 + 10;
vector<int> g[N];
int d[N];
int tin[N];
int tout[N];
int T = 0;
long long t[2][N];
long long sum(long long* t, int r) {
  long long result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result = (result + t[r]) % MOD;
  return result;
}
void inc(long long* t, int i, long long v) {
  for (; i < N; i = (i | (i + 1))) t[i] = (t[i] + v) % MOD;
}
void dfs(int v, int p = 0) {
  tin[v] = T++;
  for (int i = 0; i < int(g[v].size()); ++i) {
    if (g[v][i] != p) {
      d[g[v][i]] = d[v] + 1;
      dfs(g[v][i], v);
    }
  }
  tout[v] = T++;
}
void solve() {
  int n, m;
  scanf("%d", &n);
  for (int from = 1; from < int(n); ++from) {
    int to;
    scanf("%d", &to);
    to--;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  scanf("%d\n", &m);
  dfs(0);
  for (int i = 0; i < int(m); ++i) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int v, x, k;
      scanf("%d %d %d", &v, &x, &k);
      v--;
      long long val =
          ((((long long)x + (long long)k * (long long)d[v]) % MOD) + MOD) % MOD;
      inc(t[0], tin[v], val);
      inc(t[0], tout[v], -val);
      inc(t[1], tin[v], k);
      inc(t[1], tout[v], -k);
    } else {
      int v;
      scanf("%d", &v);
      v--;
      long long res =
          (((sum(t[0], tin[v]) - sum(t[1], tin[v]) * (long long)d[v]) % MOD) +
           MOD) %
          MOD;
      printf("%I64d\n", res);
    }
  }
}
int main() {
  srand((unsigned int)time(NULL));
  cout << setprecision(10) << fixed;
  solve();
  cerr << clock() << 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>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
template <typename T>
T sqr(const T& x) {
  return x * x;
}
template <typename T>
T my_abs(const T& x) {
  return x < 0 ? -x : x;
}
const int INF = (int)1e9;
const long long LINF = (long long)6e18;
const long long INF64 = LINF;
const long long INFLL = LINF;
const long double EPS = 1e-8;
const long double PI = 3.1415926535897932384626433832795;
const long double ME = 1e-5;
const long long MOD = (int)1e9 + 7;
const long long MOD2 = (int)1e9 + 21;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int SQN = 5000;
const int LOGN = 17;
const int N = (int)6e5 + 10;
const int M = (int)1e5 + 10;
vector<int> g[N];
int d[N];
int tin[N];
int tout[N];
int T = 0;
long long t[2][N];
long long sum(long long* t, int r) {
  long long result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result = (result + t[r]) % MOD;
  return result;
}
void inc(long long* t, int i, long long v) {
  for (; i < N; i = (i | (i + 1))) t[i] = (t[i] + v) % MOD;
}
void dfs(int v, int p = 0) {
  tin[v] = T++;
  for (int i = 0; i < int(g[v].size()); ++i) {
    if (g[v][i] != p) {
      d[g[v][i]] = d[v] + 1;
      dfs(g[v][i], v);
    }
  }
  tout[v] = T++;
}
void solve() {
  int n, m;
  scanf("%d", &n);
  for (int from = 1; from < int(n); ++from) {
    int to;
    scanf("%d", &to);
    to--;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  scanf("%d\n", &m);
  dfs(0);
  for (int i = 0; i < int(m); ++i) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int v, x, k;
      scanf("%d %d %d", &v, &x, &k);
      v--;
      long long val =
          ((((long long)x + (long long)k * (long long)d[v]) % MOD) + MOD) % MOD;
      inc(t[0], tin[v], val);
      inc(t[0], tout[v], -val);
      inc(t[1], tin[v], k);
      inc(t[1], tout[v], -k);
    } else {
      int v;
      scanf("%d", &v);
      v--;
      long long res =
          (((sum(t[0], tin[v]) - sum(t[1], tin[v]) * (long long)d[v]) % MOD) +
           MOD) %
          MOD;
      printf("%I64d\n", res);
    }
  }
}
int main() {
  srand((unsigned int)time(NULL));
  cout << setprecision(10) << fixed;
  solve();
  cerr << clock() << endl;
  return 0;
}

```