#include <bits/stdc++.h>
using namespace std;
struct state {
  long long x, k;
};
const int MAXN = 3e5 + 5;
const int TSIZE = (1 << 20);
const long long MOD = 1e9 + 7;
int N, Q, p, l[MAXN], r[MAXN];
long long depth[MAXN];
vector<int> edges[MAXN];
state tree[TSIZE];
int calcRanges(int u = 1, int d = 0) {
  l[u] = p++;
  depth[l[u]] = d;
  int size = 1;
  for (int v : edges[u]) {
    size += calcRanges(v, d + 1);
  }
  r[u] = l[u] + size;
  return size;
}
void update(int a, int b, int v, int x, int k, int i = 0, int start = 0,
            int end = MAXN) {
  if (a == start && b == end) {
    tree[i].x = (tree[i].x + depth[v] * k + x) % MOD;
    tree[i].k = (tree[i].k + k) % MOD;
    return;
  }
  int mid = (start + end) / 2;
  if (a < mid) update(a, min(b, mid), v, x, k, i * 2 + 1, start, mid);
  if (b > mid) update(max(a, mid), b, v, x, k, i * 2 + 2, mid, end);
}
long long query(int v, int i = 0, int start = 0, int end = MAXN) {
  long long ans = ((tree[i].x - depth[v] * tree[i].k) % MOD + MOD) % MOD;
  if (end - start == 1) return ans;
  int mid = (start + end) / 2;
  if (v < mid)
    ans = (ans + query(v, i * 2 + 1, start, mid)) % MOD;
  else
    ans = (ans + query(v, i * 2 + 2, mid, end)) % MOD;
  return ans;
}
int main() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
  cin >> N;
  for (int i = 2; i <= N; i++) {
    int ip;
    cin >> ip;
    edges[ip].push_back(i);
  }
  calcRanges();
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int q, v;
    cin >> q;
    if (q == 1) {
      int x, k;
      cin >> v >> x >> k;
      update(l[v], r[v], l[v], x, k);
    } else {
      cin >> v;
      cout << query(l[v]) << endl;
    }
  }
}
