#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = 1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
  if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
  if (a < val) a = val;
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  bool first = true;
  os << "[";
  for (auto i : v) {
    if (!first) os << ", ";
    os << i;
    first = false;
  }
  return os << "]";
}
const long long N = 3 * 1e5 + 10;
std::vector<long long> v[N];
long long st[N], en[N], timer = 0, n, height[N];
void dfs(long long s, long long lvl) {
  height[s] = lvl;
  st[s] = ++timer;
  for (auto it : v[s]) dfs(it, lvl + 1);
  en[s] = timer;
}
struct S {
  long long sum1 = 0, sum_k = 0;
} seg[4 * N];
void update(long long node, long long l, long long r, long long ql,
            long long qr, long long x, long long k, long long ver) {
  if (l > r or qr < l or r < ql) return;
  if (l >= ql and r <= qr) {
    long long tt = seg[node].sum1;
    (seg[node].sum1 += x) %= mod;
    (seg[node].sum1 += (k * height[ver]) % mod) %= mod;
    (seg[node].sum_k += k) %= mod;
    return;
  }
  long long mid = (l + r) >> 1;
  update(2 * node, l, mid, ql, qr, x, k, ver);
  update(2 * node + 1, mid + 1, r, ql, qr, x, k, ver);
}
long long ans = 0;
void query(long long node, long long l, long long r, long long pos,
           long long ver) {
  if (l > r) return;
  ans += seg[node].sum1;
  ans %= mod;
  ans -= (height[ver] * seg[node].sum_k) % mod;
  ans += mod;
  ans %= mod;
  if (l == r) {
    return;
  }
  long long mid = (l + r) >> 1;
  if (pos <= mid) {
    query(2 * node, l, mid, pos, ver);
  } else {
    query(2 * node + 1, mid + 1, r, pos, ver);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 2; i <= n; ++i) {
    long long par;
    cin >> par;
    v[par].push_back(i);
  }
  dfs(1, 0);
  long long q;
  cin >> q;
  while (q--) {
    long long tt;
    cin >> tt;
    if (tt == 1) {
      long long v, x, k;
      cin >> v >> x >> k;
      update(1, 1, n, st[v], en[v], x, k, v);
    } else {
      long long v;
      cin >> v;
      ans = 0;
      query(1, 1, n, st[v], v);
      cout << ans << '\n';
    }
  }
  return 0;
}
