#include <bits/stdc++.h>
using namespace std;
inline void Put(long long* s, int& t, const long long v,
                bool (*cmp)(const long long, const long long)) {
  int u = ++t;
  for (s--; 1 < u && cmp(v, s[u >> 1]); u >>= 1) s[u] = s[u >> 1];
  s[u] = v;
}
inline void Del(long long* s, int& t,
                bool (*cmp)(const long long, const long long)) {
  int u = 1, v = 2;
  for (s--, s[1] = s[t--]; v <= t; swap(s[u], s[v]), u = v, v = u << 1) {
    if (v < t && cmp(s[v | 1], s[v])) v++;
    if (!cmp(s[v], s[u])) return;
  }
}
int S[100001], n;
long long g[100001];
void del(long long* A, long long* B, int* C, int* D, const int u,
         const long long v, bool (*cmp)(const long long, const long long)) {
  if (A[S[u]] == v) {
    if (u != n) del(A, B, C, D, n, v + g[u + 1], cmp);
    for (Del(A + S[u], C[u], cmp); D[u] && A[S[u]] == B[S[u]];
         Del(B + S[u], D[u], cmp))
      Del(A + S[u], C[u], cmp);
    if (u != n && C[u]) Put(A + S[n], C[n], A[S[u]] + g[u + 1], cmp);
  } else
    Put(B + S[u], D[u], v, cmp);
}
inline void put(long long* A, long long* B, int* C, int* D, const int u,
                const long long v,
                bool (*cmp)(const long long, const long long)) {
  if (!C[u])
    Put(A + S[n], C[n], v + g[u + 1], cmp);
  else if (cmp(v, A[S[u]]))
    del(A, B, C, D, n, A[S[u]] + g[u + 1], cmp),
        Put(A + S[n], C[n], v + g[u + 1], cmp);
  Put(A + S[u], C[u], v, cmp);
}
inline bool Min(const long long u, const long long v) { return u < v; }
inline bool Max(const long long u, const long long v) { return v < u; }
int E[100001], F[100001], G[100001], H[100001], a[100001], b[100001], c[100001],
    d[100001], f[100001], i, q;
long long A[700007], B[700007], C[700007], D[700007], e[100001], h[100001];
inline void del(int u) {
  del(A, B, E, F, f[u] - 1, h[u], Min), del(C, D, G, H, f[u] - 1, h[u], Max);
}
inline void put(int u) {
  put(A, B, E, F, f[u] - 1, h[u], Min), put(C, D, G, H, f[u] - 1, h[u], Max);
}
inline void Del(int u) {
  if (E[u - 1])
    del(A, B, E, F, n, A[S[u - 1]] + g[u], Min),
        del(C, D, G, H, n, C[S[u - 1]] + g[u], Max);
}
inline void Put(int u) {
  if (E[u - 1])
    Put(A + S[n], E[n], A[S[u - 1]] + g[u], Min),
        Put(C + S[n], G[n], C[S[u - 1]] + g[u], Max);
}
int u, v, w;
int main() {
  scanf("%d%d", &n, &q);
  for (i = 1; i <= n; i++) scanf("%lld", e + i), d[i] = 1;
  for (i = 1; i <= n; i++) scanf("%d", f + i), S[f[i]]++, d[f[i]]++, d[i]++;
  for (i = 1; i <= q; i++)
    scanf("%d", a + i), a[i] == 1 ? scanf("%d%d", b + i, c + i),
        w = f[v = f[u = f[b[i]]]], S[w]++, S[v]++, w = f[v = f[u = c[i]]],
        S[w]++, S[v]++, S[u]++, swap(f[b[i]], c[i]), 0 : 0,
        a[i] == 2 ? scanf("%d", b + i) : 0;
  for (i = q; i; i--)
    if (a[i] == 1) swap(f[b[i]], c[i]);
  for (i = 1; i <= n; i++)
    g[i] = e[i] / d[i], h[i] += e[i] - (d[i] - 1) * g[i], h[f[i]] += g[i],
    S[i] += S[i - 1];
  for (i = 1; i <= n; i++)
    Put(A + S[f[i] - 1], E[f[i] - 1], h[i], Min),
        Put(C + S[f[i] - 1], G[f[i] - 1], h[i], Max);
  for (i = 1; i <= n; i++) Put(i);
  for (i = 1; i <= q; i++)
    if (a[i] == 1) {
      w = f[v = f[u = b[i]]], del(u), del(v), del(w), Del(v), h[w] -= g[v],
      h[v] -= g[u];
      h[v] += --d[v] * g[v], g[v] = e[v] / d[v], h[v] -= (d[v] - 1) * g[v],
                             h[w] += g[v], Put(v), put(w), put(v);
      w = f[v = f[u] = c[i]], del(v), del(w), Del(v), h[w] -= g[v],
      h[v] += g[u];
      h[v] += (d[v] - 1) * g[v],
          g[v] = e[v] / ++d[v], h[v] -= (d[v] - 1) * g[v], h[w] += g[v], Put(v),
          put(w), put(v), put(u);
    } else if (a[i] == 2)
      printf("%I64d\n", h[b[i]] + g[f[b[i]]]);
    else if (a[i] == 3)
      printf("%I64d %I64d\n", A[S[n]], C[S[n]]);
  return 0;
}
