#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 * 100 + 17, mod = 1000 * 1000 * 1000 + 7;
int n, mark[maxn], fin[maxn], str[maxn], timi, place[maxn];
long long V1[4 * maxn], V0[4 * maxn], d[maxn];
vector<int> G[maxn], VET;
void dfs(int u) {
  mark[u] = 1;
  str[u] = timi++;
  for (int i = 0; i < (int)G[u].size(); i++) {
    d[G[u][i]] = d[u] + 1;
    dfs(G[u][i]);
  }
  fin[u] = timi++;
}
bool comPAIR(int i, int j) { return str[i] < str[j]; }
int L(int u) { return 2 * u + 1; }
int R(int u) { return 2 * u + 2; }
void up_child(int id) {
  V0[L(id)] += V0[id], V0[L(id)] %= mod;
  V1[L(id)] += V1[id], V1[L(id)] %= mod;
  V0[R(id)] += V0[id], V0[R(id)] %= mod;
  V1[R(id)] += V1[id], V1[R(id)] %= mod;
  V0[id] = V1[id] = 0;
}
void add_seg(int a, int b, int fi, int se, int id, long long VAL0,
             long long VAL1) {
  if (fi >= b || a >= se) return;
  if (a == fi and b == se) {
    V0[id] += VAL0, V0[id] %= mod;
    V1[id] += VAL1, V1[id] %= mod;
    return;
  }
  up_child(id);
  int mid = (fi + se) / 2;
  add_seg(a, min(b, mid), fi, mid, L(id), VAL0, VAL1);
  add_seg(max(a, mid), b, mid, se, R(id), VAL0, VAL1);
}
void add(int v, long long x, long long k) {
  str[n] = str[v], str[n + 1] = fin[v];
  int l = lower_bound(VET.begin(), VET.end(), n, comPAIR) - VET.begin();
  int r = lower_bound(VET.begin(), VET.end(), n + 1, comPAIR) - VET.begin();
  str[n] = str[n + 1] = 0;
  add_seg(l, r, 0, n, 0, (x + 1ll * d[v] * k) % mod, k);
}
int get_val(int a, int fi, int se, int id, int dis) {
  if (fi == se - 1) return (V0[id] - (1ll * dis * V1[id]) % mod) % mod;
  up_child(id);
  int mid = (fi + se) / 2;
  if (a < mid) return get_val(a, fi, mid, L(id), dis);
  return get_val(a, mid, se, R(id), dis);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a;
    scanf("%d", &a);
    a--;
    G[a].push_back(i);
  }
  dfs(0);
  for (int i = 0; i < n; i++) VET.push_back(i);
  sort(VET.begin(), VET.end(), comPAIR);
  for (int i = 0; i < n; i++) place[VET[i]] = i;
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int v, x, k;
      scanf("%d %d %d", &v, &x, &k);
      v--;
      add(v, x, k);
    } else {
      int v;
      scanf("%d", &v);
      v--;
      printf("%d\n", (get_val(place[v], 0, n, 0, d[v]) + mod) % mod);
    }
  }
}
