#include <bits/stdc++.h>
using namespace std;
const int maxN = 101000;
const int inf = 2147483647;
int n, Q;
long long A[maxN], B[maxN], C[maxN], D[maxN], E[maxN], Delta[maxN], S[maxN];
multiset<long long> MS[maxN];
multiset<long long> Min, Max;
inline void UpdateE(int u, long long key);
inline void UpdateC(int u, long long key);
inline void UpdateD(int u, long long key);
inline void Add(int u, long long key);
inline void Del(int u, long long key);
inline void Modify(int u, long long key);
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; i++) scanf("%lld", &B[i]);
  for (int i = 1; i <= n; i++) scanf("%lld", &A[i]);
  for (int i = 1; i <= n; i++) D[i] += 2, D[A[i]]++;
  for (int i = 1; i <= n; i++) E[i] = B[i] / D[i];
  for (int i = 1; i <= n; i++) S[A[i]] += E[i];
  for (int i = 1; i <= n; i++)
    C[i] = B[i] - D[i] * E[i] + S[i] + E[i] + E[A[i]], MS[A[i]].insert(C[i]);
  for (int i = 1; i <= n; i++)
    if (MS[i].empty() == 0)
      Min.insert(*MS[i].begin()), Max.insert(*(--MS[i].end()));
  while (Q--) {
    int opt;
    scanf("%d", &opt);
    if (opt == 1) {
      int u, w;
      scanf("%d%d", &u, &w);
      int v = A[u];
      C[u] = C[u] + Delta[v];
      UpdateC(v, C[v] - E[u]);
      Del(v, C[u]);
      C[u] = C[u] - E[v];
      UpdateD(v, D[v] - 1);
      UpdateE(v, B[v] / D[v]);
      UpdateD(w, D[w] + 1);
      UpdateE(w, B[w] / D[w]);
      C[u] = C[u] + E[w];
      Add(w, C[u]);
      UpdateC(w, C[w] + E[u]);
      C[u] = C[u] - Delta[w];
      A[u] = w;
    }
    if (opt == 2) {
      int p;
      scanf("%d", &p);
      printf("%lld\n", C[p] + Delta[A[p]]);
    }
    if (opt == 3) printf("%lld %lld\n", (*Min.begin()), (*(--Max.end())));
  }
  return 0;
}
inline void UpdateD(int u, long long key) {
  UpdateE(u, B[u] / D[u]);
  UpdateC(u, C[u] + D[u] * E[u]);
  D[u] = key;
  UpdateC(u, C[u] - D[u] * E[u]);
  return;
}
inline void UpdateE(int u, long long key) {
  UpdateC(A[u], C[A[u]] - E[u]);
  UpdateC(u, C[u] - E[u] + D[u] * E[u]);
  Modify(u, key - E[u]);
  E[u] = key;
  UpdateC(A[u], C[A[u]] + E[u]);
  UpdateC(u, C[u] + E[u] - D[u] * E[u]);
  return;
}
inline void UpdateC(int u, long long key) {
  Del(A[u], C[u] + Delta[A[u]]);
  C[u] = key;
  Add(A[u], C[u] + Delta[A[u]]);
  return;
}
inline void Add(int u, long long key) {
  if (MS[u].empty() == 0) {
    Min.erase(Min.find(Delta[u] + (*MS[u].begin())));
    Max.erase(Max.find(Delta[u] + (*(--MS[u].end()))));
  }
  key = key - Delta[u];
  MS[u].insert(key);
  Min.insert(Delta[u] + (*MS[u].begin()));
  Max.insert(Delta[u] + (*(--MS[u].end())));
  return;
}
void Del(int u, long long key) {
  if (MS[u].empty() == 0) {
    Min.erase(Min.find(Delta[u] + (*MS[u].begin())));
    Max.erase(Max.find(Delta[u] + (*(--MS[u].end()))));
  }
  key -= Delta[u];
  MS[u].erase(MS[u].find(key));
  if (MS[u].empty() == 0) {
    Min.insert(Delta[u] + (*MS[u].begin()));
    Max.insert(Delta[u] + (*(--MS[u].end())));
  }
  return;
}
inline void Modify(int u, long long key) {
  if (MS[u].empty() == 0) {
    Min.erase(Min.find(Delta[u] + (*MS[u].begin())));
    Max.erase(Max.find(Delta[u] + (*(--MS[u].end()))));
  }
  Delta[u] += key;
  if (MS[u].empty() == 0) {
    Min.insert(Delta[u] + (*MS[u].begin()));
    Max.insert(Delta[u] + (*(--MS[u].end())));
  }
  return;
}
