#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0ll, f = 1ll;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1ll;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1ll) + (x << 3ll) + (ch - '0');
    ch = getchar();
  }
  return x * f;
}
multiset<long long> ans, Son[100005];
long long A[100005];
long long B[100005];
long long E[100005];
long long F[100005];
long long in[100005];
long long Sum[100005];
inline void Update(long long i) {
  E[i] = B[i] / (in[i] + 2);
  F[i] = B[i] - (in[i] + 1) * E[i];
}
inline long long End(multiset<long long>& P) {
  multiset<long long>::iterator it = P.end();
  it--;
  return *it;
}
inline long long Begin(multiset<long long>& P) {
  multiset<long long>::iterator it = P.begin();
  return *it;
}
inline void DelAns(long long i) {
  if (Son[i].size() == 0) return;
  ans.erase(ans.find(Begin(Son[i]) + E[i]));
  ans.erase(ans.find(End(Son[i]) + E[i]));
}
inline void AddAns(long long i) {
  if (Son[i].size() == 0) return;
  ans.insert(Begin(Son[i]) + E[i]);
  ans.insert(End(Son[i]) + E[i]);
}
inline void AddSon(long long i) { Son[A[i]].insert(F[i] + Sum[i]); }
inline void DelSon(long long i) {
  Son[A[i]].erase(Son[A[i]].find(F[i] + Sum[i]));
}
int main() {
  long long n = read(), q = read();
  for (register long long i = 1; i <= n; ++i) {
    B[i] = read();
  }
  memset(in, 0, sizeof(in));
  for (register long long i = 1; i <= n; ++i) {
    A[i] = read();
    in[A[i]]++;
  }
  for (register long long i = 1; i <= n; ++i) {
    Update(i);
    Sum[A[i]] += E[i];
  }
  for (register long long i = 1; i <= n; ++i) {
    AddSon(i);
  }
  for (register long long i = 1; i <= n; ++i) {
    AddAns(i);
  }
  while (q--) {
    long long opr = read();
    if (opr == 1) {
      long long i = read(), j = read();
      if (A[i] == j) continue;
      DelAns(A[i]), DelAns(A[A[i]]), DelAns(A[A[A[i]]]);
      DelSon(i), DelSon(A[i]), DelSon(A[A[i]]);
      in[A[i]]--;
      Sum[A[i]] -= E[i];
      Sum[A[A[i]]] -= E[A[i]];
      Update(A[i]);
      Sum[A[A[i]]] += E[A[i]];
      AddSon(A[i]), AddSon(A[A[i]]);
      AddAns(A[i]), AddAns(A[A[i]]), AddAns(A[A[A[i]]]);
      A[i] = j;
      DelAns(A[i]), DelAns(A[A[i]]), DelAns(A[A[A[i]]]);
      DelSon(A[i]), DelSon(A[A[i]]);
      in[A[i]]++;
      Sum[A[i]] += E[i];
      Sum[A[A[i]]] -= E[A[i]];
      Update(A[i]);
      Sum[A[A[i]]] += E[A[i]];
      AddSon(i), AddSon(A[i]), AddSon(A[A[i]]);
      AddAns(A[i]), AddAns(A[A[i]]), AddAns(A[A[A[i]]]);
    } else if (opr == 2) {
      long long i = read();
      printf("%lld\n", Sum[i] + F[i] + E[A[i]]);
    } else {
      printf("%lld %lld\n", Begin(ans), End(ans));
    }
  }
}
