#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int MOD = 1000000007;
struct Tree {
  int left, right;
  int x, k;
} L[N << 2];
int n, q, idx, l[N], r[N], id[N], dep[N], p[N];
vector<int> e[N];
void build(int step, int l, int r) {
  L[step].left = l;
  L[step].right = r;
  if (l == r) return;
  int m = (l + r) >> 1;
  build(step << 1, l, m);
  build(step << 1 | 1, m + 1, r);
}
void dfs(int u, int pre, int d) {
  id[u] = ++idx;
  l[u] = idx;
  id[u] = idx;
  dep[u] = d;
  p[idx] = u;
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    if (v == pre) continue;
    dfs(v, u, d + 1);
  }
  r[u] = idx;
}
inline int add(int a, int b) { return ((a + b) % MOD + MOD) % MOD; }
void update(int step, int l, int r, int X, int K);
void push_down(int step) {
  int l = L[step].left, r = L[step].right, m = (l + r) >> 1;
  if (L[step].x || L[step].k) {
    update(step << 1, l, m, L[step].x, L[step].k);
    update(step << 1 | 1, m + 1, r, L[step].x, L[step].k);
    L[step].x = L[step].k = 0;
  }
}
void update(int step, int l, int r, int X, int K) {
  if (L[step].left == l && L[step].right == r) {
    L[step].x = add(L[step].x, X);
    L[step].k = add(L[step].k, K);
    return;
  }
  push_down(step);
  int m = (L[step].left + L[step].right) >> 1;
  if (r <= m)
    update(step << 1, l, r, X, K);
  else if (l > m)
    update(step << 1 | 1, l, r, X, K);
  else {
    update(step << 1, l, m, X, K);
    update(step << 1 | 1, m + 1, r, X, K);
  }
}
int query(int step, int pos) {
  if (L[step].left == L[step].right) {
    return add(L[step].x, -L[step].k * 1LL * dep[p[pos]] % MOD);
  }
  push_down(step);
  int m = (L[step].left + L[step].right) >> 1;
  if (pos <= m)
    return query(step << 1, pos);
  else
    return query(step << 1 | 1, pos);
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    e[p].push_back(i);
  }
  dfs(1, 0, 0);
  scanf("%d", &q);
  build(1, 1, n);
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int v, x, k;
      scanf("%d %d %d", &v, &x, &k);
      update(1, l[v], r[v], (x + 1LL * dep[v] * k) % MOD, k);
    } else {
      int v;
      scanf("%d", &v);
      printf("%d\n", query(1, id[v]));
    }
  }
  return 0;
}
