#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 4e5 + 5;

vector<int> g[nmax];
ll C[nmax], p[nmax];
ll sum[nmax];

void add(int node, ll val, int D) {
   //cerr << node << " += " << val << '\n';
   sum[node] += val;
   if(D == 0 || node == 1) return;
   add(p[node], val, D - 1);
   return;
}

signed main() {
   cin.tie(0) -> sync_with_stdio(0);
   int n, q, h;
   cin >> n >> q >> h;
   for(int i = 1; i <= n; i++) {
      cin >> C[i];
   }
   for(int i = 2, x; i <= n; i++) {
      cin >> x;
      g[x].emplace_back(i);
      p[i] = x;
      add(i, C[i], h);
   }
   add(1, C[1], h);
   
   for(int i = 1, t, c, f; i <= q; i++) {
      cin >> t;
      if(t == 1) {
         cin >> c >> f;
         n++;
         p[n] = f;
         C[n] = c;
         add(n, c, h);
      }
      else if(t == 2) {
         cin >> f >> c;
         add(f, -C[f], h);
         add(f, c, h);
         C[f] = c;
      }
      else if(t == 3) {
         cin >> f;
         add(f, -C[f], h);
      }
      else {
         cin >> f;
         cout << sum[f] << '\n';
      }
   }
}

/**
      Ovaj podrum ima hladan sjaj\Iako je to bolje od gomile drugih
--
*/ 
