#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline void read(int &x) {
  char c = nc(), b = 1;
  for (; !(c >= '0' && c <= '9'); c = nc())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
  x *= b;
}
inline void read(long long &x) {
  char c = nc(), b = 1;
  for (; !(c >= '0' && c <= '9'); c = nc())
    if (c == '-') b = -1;
  for (x = 0; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
  x *= b;
}
const int N = 100005;
int n, Q;
int A[N], D[N];
long long B[N], val[N], F[N], E[N];
multiset<long long> Ans, Son[N];
inline void Add(int x) {
  if (Son[x].empty()) return;
  Ans.insert(E[x] + *Son[x].begin());
  set<long long>::iterator it = Son[x].end();
  it--;
  Ans.insert(E[x] + *it);
}
inline void Del(int x) {
  if (Son[x].empty()) return;
  Ans.erase(Ans.find(E[x] + *Son[x].begin()));
  set<long long>::iterator it = Son[x].end();
  it--;
  Ans.erase(Ans.find(E[x] + *it));
}
int main() {
  int order, x, y;
  long long lastE, lastF, llastF, lastval;
  read(n);
  read(Q);
  for (int i = 1; i <= n; i++) read(B[i]);
  for (int i = 1; i <= n; i++) read(A[i]), D[A[i]]++;
  for (int i = 1; i <= n; i++) {
    E[i] = B[i] / (D[i] + 2);
    val[i] = B[i] - (D[i] + 1) * E[i];
    F[A[i]] += E[i];
  }
  for (int i = 1; i <= n; i++) Son[A[i]].insert(F[i] + val[i]);
  for (int i = 1; i <= n; i++) Add(i);
  while (Q--) {
    read(order);
    if (order == 1) {
      read(x);
      read(y);
      int a = A[x], b = A[A[x]], c = A[A[A[x]]];
      Del(a);
      Del(b);
      Del(c);
      lastF = F[a];
      F[a] -= E[x];
      lastE = E[a];
      D[a]--;
      E[a] = B[a] / (D[a] + 2);
      lastval = val[a];
      val[a] = B[a] - (D[a] + 1) * E[a];
      Son[a].erase(Son[a].find(F[x] + val[x]));
      llastF = F[b];
      F[b] -= lastE;
      F[b] += E[A[x]];
      Son[b].erase(Son[b].find(lastF + lastval));
      Son[b].insert(F[a] + val[a]);
      Son[c].erase(Son[c].find(llastF + val[b]));
      Son[c].insert(F[b] + val[b]);
      Add(a);
      Add(b);
      Add(c);
      A[x] = y;
      a = A[x], b = A[A[x]], c = A[A[A[x]]];
      Del(a);
      Del(b);
      Del(c);
      lastF = F[a];
      F[a] += E[x];
      lastE = E[a];
      D[a]++;
      E[a] = B[a] / (D[a] + 2);
      lastval = val[a];
      val[a] = B[a] - (D[a] + 1) * E[a];
      Son[a].insert(F[x] + val[x]);
      llastF = F[b];
      F[b] -= lastE;
      F[b] += E[A[x]];
      Son[b].erase(Son[b].find(lastF + lastval));
      Son[b].insert(F[a] + val[a]);
      Son[c].erase(Son[c].find(llastF + val[b]));
      Son[c].insert(F[b] + val[b]);
      Add(a);
      Add(b);
      Add(c);
    } else if (order == 2) {
      read(x);
      printf("%I64d\n", val[x] + F[x] + E[A[x]]);
    } else {
      printf("%I64d ", *Ans.begin());
      set<long long>::iterator it = Ans.end();
      it--;
      printf("%I64d\n", *it);
    }
  }
}
