#include <bits/stdc++.h>
using namespace std;
const int M = 300010, mod = 1000000007;
vector<int> G[M];
int done[M], visited[M], parent[M], subtr[M];
int L[M], R[M], lev[M];
long long val[M], ds[M];
int calc_subtree(int u) {
  int i, v, sum = 0;
  visited[u] = true;
  for (i = 0; i < G[u].size(); i++) {
    v = G[u][i];
    if (!visited[v] && !done[v]) sum += calc_subtree(v);
  }
  visited[u] = false;
  return subtr[u] = sum + 1;
}
void decompose(int u, int p) {
  int n = calc_subtree(u), i, v, tempP = -1;
  if (n == 1) {
    parent[u] = p;
    return;
  }
  while (true) {
    bool found = false;
    for (i = 0; i < G[u].size(); i++) {
      v = G[u][i];
      if (!done[v] && v != tempP && subtr[v] > n / 2) {
        found = true;
        tempP = u;
        u = v;
        break;
      }
    }
    if (!found) break;
  }
  done[u] = true;
  parent[u] = p;
  for (i = 0; i < G[u].size(); i++)
    if (!done[G[u][i]]) decompose(G[u][i], u);
}
int TIMEE = 0;
void dfs(int u, int depth) {
  L[u] = ++TIMEE;
  visited[u] = true;
  lev[u] = depth;
  for (int v : G[u])
    if (!visited[v]) dfs(v, depth + 1);
  R[u] = TIMEE;
}
bool isdescendent(int u, int v) { return L[v] >= L[u] && R[v] <= R[u]; }
int dist(int u, int p) { return lev[u] - lev[p]; }
int main() {
  ios_base::sync_with_stdio(false);
  int i, j, k, n;
  int q, t, u, first, d;
  scanf("%d", &n);
  for (i = 2; i <= n; i++) {
    scanf("%d", &j);
    G[j].push_back(i);
    G[i].push_back(j);
  }
  memset((visited), (false), sizeof(visited));
  dfs(1, 0);
  memset((visited), (false), sizeof(visited));
  decompose(1, -1);
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d%d", &u, &first, &d);
      int v = u;
      while (v != -1) {
        if (isdescendent(u, v)) {
          val[v] += ((long long)first - (long long)dist(v, u) * (long long)d);
          ds[v] += (long long)d;
          val[v] = (val[v] % mod + mod) % mod;
          ds[v] %= mod;
        }
        v = parent[v];
      }
    } else {
      scanf("%d", &u);
      long long sum = 0;
      int p = u;
      while (p != -1) {
        if (isdescendent(p, u))
          sum += ((long long)val[p] - (long long)dist(u, p) * (long long)ds[p]);
        sum = (sum % mod + mod) % mod;
        p = parent[p];
      }
      printf("%d\n", (int)sum);
    }
  }
  return 0;
}
