#include <bits/stdc++.h>
using namespace std;
const int N = 333333;
const long long Mod = 1e9 + 7;
int P[N], H[N], St[N], Fn[N], n, Time;
vector<int> G[N];
pair<long long, long long> Seg[N << 2];
void DFS(int v = 1);
long long Sum(long long a, long long b);
long long Mul(long long a, long long b);
long long Fix(long long x);
void Add(int l, int r, int f, int s, int id = 1, int b = 0, int e = n) {
  if (l >= e || r <= b) return;
  if (l <= b && r >= e) {
    Seg[id].first = Sum(Seg[id].first, f);
    Seg[id].second = Sum(Seg[id].second, s);
    return;
  }
  Add(l, r, f, s, id << 1, b, (b + e) >> 1);
  Add(l, r, f, s, id << 1 | 1, (b + e) >> 1, e);
}
long long Get1(int p, int id = 1, int b = 0, int e = n) {
  long long ans = 0;
  ans = Sum(ans, Seg[id].first);
  if (e - b == 1) return ans;
  if (p < (b + e) >> 1)
    return (Sum(ans, Get1(p, id << 1, b, (b + e) >> 1)));
  else
    return (Sum(ans, Get1(p, id << 1 | 1, (b + e) >> 1, e)));
}
long long Get2(int p, int id = 1, int b = 0, int e = n) {
  long long ans = 0;
  ans = Sum(ans, Seg[id].second);
  if (e - b == 1) return ans;
  if (p < (b + e) >> 1)
    return (Sum(ans, Get2(p, id << 1, b, (b + e) >> 1)));
  else
    return (Sum(ans, Get2(p, id << 1 | 1, (b + e) >> 1, e)));
}
void Query() {
  long long t, v;
  cin >> t >> v;
  if (t == 1) {
    long long x, k;
    cin >> x >> k;
    long long res = Mul(k, H[v]);
    res = Sum(res, x);
    Add(St[v], Fn[v], res, Fix(-k));
  } else {
    long long ans = Get1(St[v]);
    ans = Sum(ans, Mul(H[v], Get2(St[v])));
    cout << ans << '\n';
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> P[i];
    G[P[i]].push_back(i);
  }
  DFS(1);
  int q;
  cin >> q;
  while (q--) Query();
  return (0);
}
void DFS(int v) {
  St[v] = Time++;
  for (auto u : G[v]) H[u] = H[v] + 1, DFS(u);
  Fn[v] = Time;
}
long long Fix(long long x) {
  while (x < 0) x += Mod;
  return (x % Mod);
}
long long Sum(long long a, long long b) {
  a = Fix(a);
  b = Fix(b);
  return Fix(a + b);
}
long long Mul(long long a, long long b) {
  a = Fix(a);
  b = Fix(b);
  return Fix(a * b);
}
