#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
inline long long mod_it(long long it) {
  it %= MOD;
  while (it < 0) it += MOD;
  it %= MOD;
  return it;
}
struct Result {
  long long x;
  long long k;
  Result operator+(const Result& r) {
    Result temp = {x + r.x, k + r.k};
    return temp;
  }
  void operator+=(const Result& r) {
    x += r.x;
    k += r.k;
  }
};
struct SegmentTree {
  struct Node {
    int l;
    int r;
    long long x;
    long long k;
  };
  int r_most;
  vector<Node> node;
  void init(int rm) {
    r_most = rm;
    node.resize((r_most + 1) * 4);
    Node& root = node[1];
    root.l = 0;
    root.r = r_most;
    root.x = 0;
    root.k = 0;
    for (int i = 2; i < node.size(); i++) {
      Node& cur = node[i];
      cur.x = 0;
      cur.k = 0;
      const Node& par = node[i / 2];
      if (par.l == par.r) continue;
      int m = (par.l + par.r) / 2;
      if (i & 1) {
        cur.l = m + 1;
        cur.r = par.r;
      } else {
        cur.l = par.l;
        cur.r = m;
      }
    }
    { ; }
    show();
  }
  void show() {
    { ; }
    for (int i = 1; i < node.size(); i++) {
      Node& cur = node[i];
      { ; }
    }
  }
  void update(int l, int r, long long x, long long k, int i = 1) {
    Node& cur = node[i];
    if (cur.l == cur.r) {
      cur.x = mod_it(cur.x + x);
      cur.k = mod_it(cur.k + k);
      return;
    }
    int curm = (cur.l + cur.r) / 2;
    int il = i * 2;
    int ir = il + 1;
    if (l <= cur.l && cur.r <= r) {
      cur.x = mod_it(cur.x + x);
      cur.k = mod_it(cur.k + k);
      return;
    }
    long long mmx = mod_it(x - mod_it(curm + 1 - l) * mod_it(k));
    if (l > curm && l <= cur.r) update(l, r, x, k, ir);
    if (l <= curm && curm < r) update(curm + 1, r, mmx, k, ir);
    if (l <= curm && r >= cur.l) update(l, r, x, k, il);
  }
  Result query(int l, int i = 1) {
    Node& cur = node[i];
    if (cur.l == cur.r) return (Result){cur.x, cur.k};
    long long sub = mod_it(mod_it(l - cur.l) * mod_it(cur.k));
    Result ans = {mod_it(cur.x - sub), cur.k};
    int m = (cur.l + cur.r) / 2;
    int il = i * 2;
    int ir = il + 1;
    if (l <= m)
      ans += query(l, il);
    else
      ans += query(l, ir);
    ans.x = mod_it(ans.x);
    ans.k = mod_it(ans.k);
    return ans;
  }
};
struct Graph {
  struct Edge {
    int to;
  };
  const static int MAXNODE = 300002;
  vector<int> g[MAXNODE];
  vector<Edge> edge;
  int n;
  void init(int nn) {
    n = nn;
    for (int i = 0; i <= n; i++) g[i].clear();
    edge.clear();
  }
  void add_e(int x, int y) {
    Edge e = {y};
    g[x].push_back(edge.size());
    edge.push_back(e);
  }
  int parent[MAXNODE];
  int size[MAXNODE];
  int size_parent(int cur) {
    int& s = size[cur] = 1;
    for (int ie : g[cur]) {
      const Edge& e = edge[ie];
      int nx = e.to;
      parent[nx] = cur;
      s += size_parent(nx);
    }
    return s;
  }
  void show_size_parent() {
    for (int i = 0; i <= n; i++)
      printf("node %d: size %d, parent %d\n", i, size[i], parent[i]);
  }
  struct Chain {
    int head;
    int len;
  };
  vector<Chain> chain;
  int chain_total;
  int chain_no[MAXNODE];
  int chain_pos[MAXNODE];
  void hld(int cur) {
    if (chain_total == chain.size()) {
      Chain c = {cur, 0};
      chain.push_back(c);
    }
    chain_no[cur] = chain_total;
    chain_pos[cur] = chain[chain_total].len;
    chain[chain_total].len++;
    if (g[cur].size() == 0) return;
    int heavy = edge[g[cur][0]].to;
    for (int ie : g[cur]) {
      const Edge& e = edge[ie];
      int nx = e.to;
      if (size[nx] > size[heavy]) heavy = nx;
    }
    hld(heavy);
    for (int ie : g[cur]) {
      const Edge& e = edge[ie];
      int nx = e.to;
      if (nx == heavy) continue;
      chain_total++;
      hld(nx);
    }
  }
  void heavy_light_decomposition() {
    parent[1] = -1;
    assert(n == size_parent(1));
    chain_total = 0;
    chain.clear();
    hld(1);
    chain_total++;
  }
  void show_hld() {
    printf("chain_total = %d\n", chain_total);
    for (int i = 0; i <= chain_total; i++)
      printf("chain %d: len %d, head %d\n", i, chain[i].len, chain[i].head);
    for (int i = 0; i <= n; i++)
      printf("node %d: chain %d, pos %d\n", i, chain_no[i], chain_pos[i]);
  }
  vector<SegmentTree> st;
  void init_sol() {
    st.resize(chain_total);
    for (int i = 0; i < st.size(); i++) st[i].init(chain[i].len - 1);
  }
  void update(int v, int x, int k) {
    int cn = chain_no[v];
    int cp = chain_pos[v];
    int cl = chain[cn].len;
    st[cn].update(cp, cl - 1, x, k);
  }
  long long query(int v) {
    long long ans = 0;
    int d = 0;
    do {
      int cn = chain_no[v];
      int cp = chain_pos[v];
      Result temp = st[cn].query(cp);
      long long temp_ans = temp.x - mod_it(mod_it(temp.k) * mod_it(d));
      temp_ans = mod_it(temp_ans);
      ans += temp_ans;
      ans = mod_it(ans);
      d += chain_pos[v] + 1;
      v = chain[cn].head;
      v = parent[v];
    } while (v != -1);
    return ans;
  }
};
int n;
int m;
Graph g;
int main() {
  scanf("%d", &n);
  g.init(n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    g.add_e(x, i);
  }
  g.heavy_light_decomposition();
  g.init_sol();
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int op, v, x, k;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d %d %d", &v, &x, &k);
      g.update(v, x, k);
    } else {
      scanf("%d", &v);
      printf("%d\n", g.query(v));
    }
  }
}

### 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 int MOD = 1000000007;
inline long long mod_it(long long it) {
  it %= MOD;
  while (it < 0) it += MOD;
  it %= MOD;
  return it;
}
struct Result {
  long long x;
  long long k;
  Result operator+(const Result& r) {
    Result temp = {x + r.x, k + r.k};
    return temp;
  }
  void operator+=(const Result& r) {
    x += r.x;
    k += r.k;
  }
};
struct SegmentTree {
  struct Node {
    int l;
    int r;
    long long x;
    long long k;
  };
  int r_most;
  vector<Node> node;
  void init(int rm) {
    r_most = rm;
    node.resize((r_most + 1) * 4);
    Node& root = node[1];
    root.l = 0;
    root.r = r_most;
    root.x = 0;
    root.k = 0;
    for (int i = 2; i < node.size(); i++) {
      Node& cur = node[i];
      cur.x = 0;
      cur.k = 0;
      const Node& par = node[i / 2];
      if (par.l == par.r) continue;
      int m = (par.l + par.r) / 2;
      if (i & 1) {
        cur.l = m + 1;
        cur.r = par.r;
      } else {
        cur.l = par.l;
        cur.r = m;
      }
    }
    { ; }
    show();
  }
  void show() {
    { ; }
    for (int i = 1; i < node.size(); i++) {
      Node& cur = node[i];
      { ; }
    }
  }
  void update(int l, int r, long long x, long long k, int i = 1) {
    Node& cur = node[i];
    if (cur.l == cur.r) {
      cur.x = mod_it(cur.x + x);
      cur.k = mod_it(cur.k + k);
      return;
    }
    int curm = (cur.l + cur.r) / 2;
    int il = i * 2;
    int ir = il + 1;
    if (l <= cur.l && cur.r <= r) {
      cur.x = mod_it(cur.x + x);
      cur.k = mod_it(cur.k + k);
      return;
    }
    long long mmx = mod_it(x - mod_it(curm + 1 - l) * mod_it(k));
    if (l > curm && l <= cur.r) update(l, r, x, k, ir);
    if (l <= curm && curm < r) update(curm + 1, r, mmx, k, ir);
    if (l <= curm && r >= cur.l) update(l, r, x, k, il);
  }
  Result query(int l, int i = 1) {
    Node& cur = node[i];
    if (cur.l == cur.r) return (Result){cur.x, cur.k};
    long long sub = mod_it(mod_it(l - cur.l) * mod_it(cur.k));
    Result ans = {mod_it(cur.x - sub), cur.k};
    int m = (cur.l + cur.r) / 2;
    int il = i * 2;
    int ir = il + 1;
    if (l <= m)
      ans += query(l, il);
    else
      ans += query(l, ir);
    ans.x = mod_it(ans.x);
    ans.k = mod_it(ans.k);
    return ans;
  }
};
struct Graph {
  struct Edge {
    int to;
  };
  const static int MAXNODE = 300002;
  vector<int> g[MAXNODE];
  vector<Edge> edge;
  int n;
  void init(int nn) {
    n = nn;
    for (int i = 0; i <= n; i++) g[i].clear();
    edge.clear();
  }
  void add_e(int x, int y) {
    Edge e = {y};
    g[x].push_back(edge.size());
    edge.push_back(e);
  }
  int parent[MAXNODE];
  int size[MAXNODE];
  int size_parent(int cur) {
    int& s = size[cur] = 1;
    for (int ie : g[cur]) {
      const Edge& e = edge[ie];
      int nx = e.to;
      parent[nx] = cur;
      s += size_parent(nx);
    }
    return s;
  }
  void show_size_parent() {
    for (int i = 0; i <= n; i++)
      printf("node %d: size %d, parent %d\n", i, size[i], parent[i]);
  }
  struct Chain {
    int head;
    int len;
  };
  vector<Chain> chain;
  int chain_total;
  int chain_no[MAXNODE];
  int chain_pos[MAXNODE];
  void hld(int cur) {
    if (chain_total == chain.size()) {
      Chain c = {cur, 0};
      chain.push_back(c);
    }
    chain_no[cur] = chain_total;
    chain_pos[cur] = chain[chain_total].len;
    chain[chain_total].len++;
    if (g[cur].size() == 0) return;
    int heavy = edge[g[cur][0]].to;
    for (int ie : g[cur]) {
      const Edge& e = edge[ie];
      int nx = e.to;
      if (size[nx] > size[heavy]) heavy = nx;
    }
    hld(heavy);
    for (int ie : g[cur]) {
      const Edge& e = edge[ie];
      int nx = e.to;
      if (nx == heavy) continue;
      chain_total++;
      hld(nx);
    }
  }
  void heavy_light_decomposition() {
    parent[1] = -1;
    assert(n == size_parent(1));
    chain_total = 0;
    chain.clear();
    hld(1);
    chain_total++;
  }
  void show_hld() {
    printf("chain_total = %d\n", chain_total);
    for (int i = 0; i <= chain_total; i++)
      printf("chain %d: len %d, head %d\n", i, chain[i].len, chain[i].head);
    for (int i = 0; i <= n; i++)
      printf("node %d: chain %d, pos %d\n", i, chain_no[i], chain_pos[i]);
  }
  vector<SegmentTree> st;
  void init_sol() {
    st.resize(chain_total);
    for (int i = 0; i < st.size(); i++) st[i].init(chain[i].len - 1);
  }
  void update(int v, int x, int k) {
    int cn = chain_no[v];
    int cp = chain_pos[v];
    int cl = chain[cn].len;
    st[cn].update(cp, cl - 1, x, k);
  }
  long long query(int v) {
    long long ans = 0;
    int d = 0;
    do {
      int cn = chain_no[v];
      int cp = chain_pos[v];
      Result temp = st[cn].query(cp);
      long long temp_ans = temp.x - mod_it(mod_it(temp.k) * mod_it(d));
      temp_ans = mod_it(temp_ans);
      ans += temp_ans;
      ans = mod_it(ans);
      d += chain_pos[v] + 1;
      v = chain[cn].head;
      v = parent[v];
    } while (v != -1);
    return ans;
  }
};
int n;
int m;
Graph g;
int main() {
  scanf("%d", &n);
  g.init(n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    g.add_e(x, i);
  }
  g.heavy_light_decomposition();
  g.init_sol();
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int op, v, x, k;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d %d %d", &v, &x, &k);
      g.update(v, x, k);
    } else {
      scanf("%d", &v);
      printf("%d\n", g.query(v));
    }
  }
}

```