#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 3e5 + 3;
vector<int> edges[MAXN];
int depth[MAXN];
int seg[1048576];
int lazy[1048576];
int seg2[1048576];
int lazy2[1048576];
int dfs_cnt;
int dfs_lo[MAXN], dfs_hi[MAXN];
void dfs(int i, int par) {
  dfs_lo[i] = ++dfs_cnt;
  for (int j = 0; j < (int)(edges[i].size()); j++) {
    int v = edges[i][j];
    if (v == par) continue;
    depth[v] = depth[i] + 1;
    dfs(v, i);
  }
  dfs_hi[i] = dfs_cnt;
}
void ust(int l, int r, int a, int b, int v, int i) {
  if (lazy[i] != 0) {
    seg[i] += (r - l + 1) * (long long)lazy[i] % MOD;
    if (seg[i] >= MOD) {
      seg[i] -= MOD;
    }
    if (l != r) {
      lazy[2 * i + 1] += lazy[i];
      if (lazy[2 * i + 1] >= MOD) lazy[2 * i + 1] -= MOD;
      lazy[2 * i + 2] += lazy[i];
      if (lazy[2 * i + 2] >= MOD) lazy[2 * i + 2] -= MOD;
    }
    lazy[i] = 0;
  }
  if (l > b || r < a) return;
  if (l >= a && r <= b) {
    seg[i] += (r - l + 1) * (long long)v % MOD;
    if (seg[i] >= MOD) {
      seg[i] -= MOD;
    }
    if (l != r) {
      lazy[2 * i + 1] += v;
      if (lazy[2 * i + 1] >= MOD) lazy[2 * i + 1] -= MOD;
      lazy[2 * i + 2] += v;
      if (lazy[2 * i + 2] >= MOD) lazy[2 * i + 2] -= MOD;
    }
    return;
  }
  int mid = (l + r) >> 1;
  ust(l, mid, a, b, v, 2 * i + 1);
  ust(mid + 1, r, a, b, v, 2 * i + 2);
  seg[i] = seg[2 * i + 1] + seg[2 * i + 2];
  if (seg[i] >= MOD) {
    seg[i] -= MOD;
  }
}
void ust2(int l, int r, int a, int b, int v, int i) {
  if (lazy2[i] != 0) {
    seg2[i] += (r - l + 1) * (long long)lazy2[i] % MOD;
    if (seg2[i] >= MOD) {
      seg2[i] -= MOD;
    }
    if (l != r) {
      lazy2[2 * i + 1] += lazy2[i];
      if (lazy2[2 * i + 1] >= MOD) lazy2[2 * i + 1] -= MOD;
      lazy2[2 * i + 2] += lazy2[i];
      if (lazy2[2 * i + 2] >= MOD) lazy2[2 * i + 2] -= MOD;
    }
    lazy2[i] = 0;
  }
  if (l > b || r < a) return;
  if (l >= a && r <= b) {
    seg2[i] += (r - l + 1) * (long long)v % MOD;
    if (seg2[i] >= MOD) {
      seg2[i] -= MOD;
    }
    if (l != r) {
      lazy2[2 * i + 1] += v;
      if (lazy2[2 * i + 1] >= MOD) lazy2[2 * i + 1] -= MOD;
      lazy2[2 * i + 2] += v;
      if (lazy2[2 * i + 2] >= MOD) lazy2[2 * i + 2] -= MOD;
    }
    return;
  }
  int mid = (l + r) >> 1;
  ust2(l, mid, a, b, v, 2 * i + 1);
  ust2(mid + 1, r, a, b, v, 2 * i + 2);
  seg2[i] = seg2[2 * i + 1] + seg2[2 * i + 2];
  if (seg2[i] >= MOD) {
    seg2[i] -= MOD;
  }
}
int qst(int l, int r, int a, int b, int i) {
  if (lazy[i] != 0) {
    seg[i] += (r - l + 1) * (long long)lazy[i] % MOD;
    if (seg[i] >= MOD) {
      seg[i] -= MOD;
    }
    if (l != r) {
      lazy[2 * i + 1] += lazy[i];
      if (lazy[2 * i + 1] >= MOD) lazy[2 * i + 1] -= MOD;
      lazy[2 * i + 2] += lazy[i];
      if (lazy[2 * i + 2] >= MOD) lazy[2 * i + 2] -= MOD;
    }
    lazy[i] = 0;
  }
  if (l > b || r < a) return 0;
  if (l >= a && r <= b) return seg[i];
  int mid = (l + r) >> 1;
  int left = qst(l, mid, a, b, 2 * i + 1);
  int right = qst(mid + 1, r, a, b, 2 * i + 2);
  return (left + right) % MOD;
}
int qst2(int l, int r, int a, int b, int i) {
  if (lazy2[i] != 0) {
    seg2[i] += (r - l + 1) * (long long)lazy2[i] % MOD;
    if (seg2[i] >= MOD) {
      seg2[i] -= MOD;
    }
    if (l != r) {
      lazy2[2 * i + 1] += lazy2[i];
      if (lazy2[2 * i + 1] >= MOD) lazy2[2 * i + 1] -= MOD;
      lazy2[2 * i + 2] += lazy2[i];
      if (lazy2[2 * i + 2] >= MOD) lazy2[2 * i + 2] -= MOD;
    }
    lazy2[i] = 0;
  }
  if (l > b || r < a) return 0;
  if (l >= a && r <= b) return seg2[i];
  int mid = (l + r) >> 1;
  int left = qst2(l, mid, a, b, 2 * i + 1);
  int right = qst2(mid + 1, r, a, b, 2 * i + 2);
  return (left + right) % MOD;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    --p;
    edges[p].push_back(i);
    edges[i].push_back(p);
  }
  dfs_cnt = -1;
  depth[0] = 0;
  dfs(0, -1);
  int q;
  cin >> q;
  for (int qq = 0; qq < q; qq++) {
    int type;
    cin >> type;
    if (type == 1) {
      int v, x, k;
      cin >> v >> x >> k;
      --v;
      int v1 = (x + depth[v] * (long long)k % MOD) % MOD;
      int v2 = k;
      ust(0, dfs_cnt, dfs_lo[v], dfs_hi[v], v1, 0);
      ust2(0, dfs_cnt, dfs_lo[v], dfs_hi[v], v2, 0);
    } else {
      int v;
      cin >> v;
      --v;
      int result = (qst(0, dfs_cnt, dfs_lo[v], dfs_lo[v], 0) -
                    qst2(0, dfs_cnt, dfs_lo[v], dfs_lo[v], 0) *
                        (long long)depth[v] % MOD +
                    MOD) %
                   MOD;
      cout << result << '\n';
    }
  }
  return 0;
}
