#include <bits/stdc++.h>
using namespace std;
int n, q;
long long A[100005], B[100005], C[100005], D[100005], E[100005];
multiset<long long> son[100005], Ans;
namespace IO {
const int Rlen = 1 << 22 | 1;
char buf[Rlen], *p1, *p2;
inline char gc() {
  return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, Rlen, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <typename T>
inline T Read() {
  char c;
  T x;
  while (!isdigit(c = gc()))
    ;
  x = c ^ 48;
  while (isdigit(c = gc())) x = (x + (x << 2) << 1) + (c ^ 48);
  return x;
}
inline int gi() { return Read<int>(); }
inline long long gl() { return Read<long long>(); }
}  // namespace IO
using IO::gi;
using IO::gl;
void Insert(int x) {
  if (!son[x].empty()) {
    Ans.insert(E[x] + *son[x].begin());
    Ans.insert(E[x] + *son[x].rbegin());
  }
}
void Delete(int x) {
  if (!son[x].empty()) {
    Ans.erase(Ans.find(E[x] + *son[x].begin()));
    Ans.erase(Ans.find(E[x] + *son[x].rbegin()));
  }
}
void ins(int fa, int x) { son[fa].insert(C[x]); }
void del(int fa, int x) { son[fa].erase(son[fa].find(C[x])); }
void Modify(int i, int j) {
  int x = A[i], y = A[x], z = A[y];
  Delete(x), Delete(y), Delete(z);
  del(z, y), del(y, x), del(x, i);
  C[y] -= E[x], C[x] -= E[i] - E[x] * (D[x] - 1);
  --D[x], E[x] = B[x] / D[x];
  C[y] += E[x], C[x] -= E[x] * (D[x] - 1);
  ins(y, x), ins(z, y);
  Insert(x), Insert(y), Insert(z);
  A[i] = j, x = A[j], y = A[x];
  Delete(j), Delete(x), Delete(y);
  del(y, x), del(x, j);
  C[x] -= E[j], C[j] += E[j] * (D[j] - 1);
  ++D[j], E[j] = B[j] / D[j];
  C[x] += E[j], C[j] -= E[j] * (D[j] - 1) - E[i];
  ins(j, i), ins(x, j), ins(y, x);
  Insert(j), Insert(x), Insert(y);
}
int main() {
  n = gi(), q = gi();
  for (int i = 1; i <= n; ++i) B[i] = gl(), D[i] = 2;
  for (int i = 1; i <= n; ++i) A[i] = gi(), D[A[i]]++;
  for (int i = 1; i <= n; ++i) E[i] = B[i] / D[i];
  for (int i = 1; i <= n; ++i)
    C[i] += B[i] - E[i] * (D[i] - 1), C[A[i]] += E[i];
  for (int i = 1; i <= n; ++i) ins(A[i], i);
  for (int i = 1; i <= n; ++i) Insert(i);
  int op, x, y;
  while (q--) {
    op = gi();
    if (op == 1)
      x = gi(), y = gi(), Modify(x, y);
    else if (op == 2)
      x = gi(), printf("%I64d\n", C[x] + E[A[x]]);
    else
      printf("%I64d %I64d\n", *Ans.begin(), *Ans.rbegin());
  }
  return 0;
}
