#include <bits/stdc++.h>
namespace IO {
inline char gc() {
  static const int Rlen = 1 << 22 | 1;
  static char buf[Rlen], *p1, *p2;
  return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, Rlen, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <typename T>
inline T get() {
  char c;
  T num;
  while (!isdigit(c = gc()))
    ;
  num = c ^ 48;
  while (isdigit(c = gc())) num = (num + (num << 2) << 1) + (c ^ 48);
  return num;
}
inline int gi() { return get<int>(); }
inline long long gl() { return get<long long>(); }
}  // namespace IO
using namespace IO;
using std::cerr;
using std::cout;
const int N = 1e5 + 7;
int n, q;
int A[N], to[N];
long long B[N], E[N], C[N];
std::multiset<long long> son[N], Ans;
inline void Del(int i) {
  if (!son[i].empty()) {
    Ans.erase(Ans.find(E[i] + *son[i].begin()));
    Ans.erase(Ans.find(E[i] + *son[i].rbegin()));
  }
}
inline void Ins(int i) {
  if (!son[i].empty()) {
    Ans.insert(E[i] + *son[i].begin());
    Ans.insert(E[i] + *son[i].rbegin());
  }
}
inline void del(int f, int u) { son[f].erase(son[f].find(C[u])); }
inline void ins(int f, int u) { son[f].insert(C[u]); }
inline void work_modify() {
  int i = gi(), j = gi();
  if (A[i] == j) return;
  int f = A[i], ff = A[f], fff = A[ff];
  Del(f), Del(ff), Del(fff);
  del(fff, ff);
  del(ff, f);
  del(f, i);
  C[ff] -= E[f], C[f] -= E[i] - E[f] * (to[f] - 1);
  --to[f], E[f] = B[f] / to[f], C[ff] += E[f], C[f] -= E[f] * (to[f] - 1);
  ins(ff, f);
  ins(fff, ff);
  Ins(f), Ins(ff), Ins(fff);
  A[i] = j;
  f = A[j], ff = A[f];
  Del(j), Del(f), Del(ff);
  del(ff, f), del(f, j);
  C[f] -= E[j], C[j] += E[j] * (to[j] - 1);
  ++to[j], E[j] = B[j] / to[j], C[j] += E[i] - E[j] * (to[j] - 1), C[f] += E[j];
  ins(j, i), ins(f, j), ins(ff, f);
  Ins(j), Ins(f), Ins(ff);
}
signed main() {
  n = gi();
  q = gi();
  for (int register i = 1; i <= n; ++i) B[i] = gl();
  for (int register i = 1; i <= n; ++i) A[i] = gi(), ++to[A[i]], to[i] += 2;
  for (int register i = 1; i <= n; ++i) E[i] = B[i] / to[i];
  for (int register i = 1; i <= n; ++i)
    C[i] += B[i] - E[i] * (to[i] - 1), C[A[i]] += E[i];
  for (int register i = 1; i <= n; ++i) ins(A[i], i);
  for (int register i = 1; i <= n; ++i) Ins(i);
  while (q--) {
    switch (gi()) {
      case 2: {
        int u = gi();
        cout << C[u] + E[A[u]] << "\n";
        break;
      }
      case 3: {
        cout << (*Ans.begin()) << " " << (*Ans.rbegin()) << "\n";
        break;
      }
      case 1:
        work_modify();
    }
  }
  return 0;
}
