#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5;
const int MOD = 1e9 + 7;
vector<int> G[MAXN + 5], chain[MAXN + 5], bitsum[MAXN + 5], bitinc[MAXN + 5];
int id[MAXN + 5], pos[MAXN + 5], sz[MAXN + 5], parent[MAXN + 5],
    level[MAXN + 5];
int allsum[MAXN + 5], allinc[MAXN + 5];
int n, qs;
void hld(int u, int dep = 0) {
  sz[u] = 1;
  level[u] = dep;
  int heaviest = -1;
  for (int v : G[u]) {
    hld(v, dep + 1);
    sz[u] += sz[v];
    if (!~heaviest || sz[heaviest] < sz[v]) heaviest = v;
  }
  if (~heaviest) {
    id[u] = id[heaviest];
    pos[u] = pos[heaviest] + 1;
  } else {
    id[u] = u;
    pos[u] = 0;
  }
  chain[id[u]].push_back(u);
}
void constructFenwicks() {
  for (int u = 0; u < n; u++) {
    bitsum[u].resize(chain[u].size() + 1);
    bitinc[u].resize(chain[u].size() + 1);
  }
}
void update(vector<int>& bit, int& all, int i, int v) {
  all += v;
  if ((all) >= MOD) all -= MOD;
  for (i++; i < bit.size(); i += i & -i) {
    bit[i] += v;
    if ((bit[i]) >= MOD) bit[i] -= MOD;
  }
}
void updateFenwicks(int u, int x, int k) {
  update(bitinc[id[u]], allinc[id[u]], chain[id[u]].size() - 1 - pos[u],
         (1LL * level[u] * k % MOD + x) % MOD);
  update(bitsum[id[u]], allsum[id[u]], chain[id[u]].size() - 1 - pos[u], k);
}
int query(const vector<int>& bit, int i) {
  int ret = 0;
  for (i++; i > 0; i -= i & -i) {
    ret += bit[i];
    if ((ret) >= MOD) ret -= MOD;
  }
  return ret;
}
int queryNode(int node) {
  int sum = 0, inc = 0;
  for (int u = node; ~u; u = parent[chain[id[u]].back()]) {
    sum += !pos[u] ? allsum[id[u]]
                   : query(bitsum[id[u]], chain[id[u]].size() - 1 - pos[u]);
    inc += !pos[u] ? allinc[id[u]]
                   : query(bitinc[id[u]], chain[id[u]].size() - 1 - pos[u]);
    if ((sum) >= MOD) sum -= MOD;
    if ((inc) >= MOD) inc -= MOD;
  }
  return (((inc - 1LL * level[node] * sum % MOD) % MOD) + MOD) % MOD;
}
int main() {
  int c, c2;
  scanf("%d", &n);
  parent[0] = -1;
  for (c = 1; c < n; c++) {
    scanf("%d", &parent[c]);
    G[--parent[c]].push_back(c);
  }
  hld(0);
  constructFenwicks();
  scanf("%d", &qs);
  for (c = 0; c < qs; c++) {
    int type, u, x, k;
    scanf("%d%d", &type, &u);
    u--;
    if (type == 1) {
      scanf("%d%d", &x, &k);
      updateFenwicks(u, x, k);
    } else {
      printf("%d\n", queryNode(u));
    }
  }
  return 0;
}
