#include <bits/stdc++.h>
const int N = 100010;
using namespace std;
int n, q;
long long A[N], B[N], C[N], D[N], E[N];
multiset<long long> son[N], Ans;
void insert(int x) {
  if (!son[x].empty()) {
    Ans.insert(E[x] + *son[x].begin());
    Ans.insert(E[x] + *son[x].rbegin());
  }
}
void delt(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];
  delt(x), delt(y), delt(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];
  delt(j), delt(x), delt(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() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) scanf("%lld", &B[i]), D[i] = 2;
  for (int i = 1; i <= n; ++i) scanf("%lld", &A[i]), 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);
  while (q--) {
    int opt, x, y;
    scanf("%d", &opt);
    if (opt == 1)
      scanf("%d%d", &x, &y), Modify(x, y);
    else if (opt == 2)
      scanf("%d", &x), printf("%lld\n", C[x] + E[A[x]]);
    else
      printf("%lld %lld\n", *Ans.begin(), *Ans.rbegin());
  }
  return 0;
}
