#include <bits/stdc++.h>
using namespace std;
multiset<long long> V[200005], S;
multiset<long long>::iterator it;
int n, m;
int to[200005], d[200005];
long long w[200005], e[200005], sume[200005], s[200005];
void inser1(int x) {
  if (V[x].size() == 0) return;
  S.insert((*V[x].begin()) + e[x]);
  S.insert((*V[x].rbegin()) + e[x]);
  return;
}
void delet1(int x) {
  if (V[x].size() == 0) return;
  S.erase(S.find((*V[x].begin()) + e[x]));
  S.erase(S.find((*V[x].rbegin()) + e[x]));
  return;
}
void inser2(int x) {
  delet1(to[x]);
  V[to[x]].insert(s[x]);
  inser1(to[x]);
}
void delet2(int x) {
  delet1(to[x]);
  V[to[x]].erase(V[to[x]].find(s[x]));
  inser1(to[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &w[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &to[i]);
  for (int i = 1; i <= n; i++) d[i] += 2, d[to[i]]++;
  for (int i = 1; i <= n; i++) e[i] = w[i] / d[i];
  for (int i = 1; i <= n; i++) sume[to[i]] += e[i];
  for (int i = 1; i <= n; i++) s[i] = w[i] - e[i] * d[i] + e[i] + sume[i];
  for (int i = 1; i <= n; i++) V[to[i]].insert(s[i]);
  for (int i = 1; i <= n; i++) inser1(i);
  while (m--) {
    int op, x, y, z;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &x, &y), z = to[x];
      long long ey = e[y], ez = e[z];
      delet2(x);
      to[x] = y;
      inser2(x);
      delet1(z), d[z]--, e[z] = w[z] / d[z], inser1(z);
      sume[z] -= e[x], sume[to[z]] += e[z] - ez;
      delet2(z), s[z] = w[z] - e[z] * d[z] + e[z] + sume[z], inser2(z);
      delet2(to[z]),
          s[to[z]] = w[to[z]] - e[to[z]] * d[to[z]] + e[to[z]] + sume[to[z]],
          inser2(to[z]);
      delet1(y), d[y]++, e[y] = w[y] / d[y], inser1(y);
      sume[y] += e[x], sume[to[y]] += e[y] - ey;
      delet2(y), s[y] = w[y] - e[y] * d[y] + e[y] + sume[y], inser2(y);
      delet2(to[y]),
          s[to[y]] = w[to[y]] - e[to[y]] * d[to[y]] + e[to[y]] + sume[to[y]],
          inser2(to[y]);
    } else if (op == 2)
      scanf("%d", &x), printf("%lld\n", s[x] + e[to[x]]);
    else if (op == 3)
      printf("%lld %lld\n", (*S.begin()), (*S.rbegin()));
  }
  return 0;
}
