#include <bits/stdc++.h>
using namespace std;
char buf[1 << 20], *p1, *p2;
template <class T>
inline void read(T &n) {
  char ch =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
           ? 0
           : *p1++);
  T w = 1, x = 0;
  while (!isdigit(ch)) {
    if (ch == '-') w = -1;
    ch =
        (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? 0
             : *p1++);
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch =
        (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? 0
             : *p1++);
  }
  n = x * w;
}
const int maxn = 100005;
long long w[maxn], f[maxn];
int n, q, a[maxn], deg[maxn], vis[maxn];
multiset<long long> s[maxn];
inline void del(int x) {
  if (!x || !vis[x] || !s[x].size()) return;
  vis[x] = 0;
  long long tmp = w[x] / (deg[x] + 1);
  s[0].erase(s[0].find((*s[x].begin()) + tmp));
  s[0].erase(s[0].find((*s[x].rbegin()) + tmp));
}
inline void add(int x) {
  if (!x || vis[x] || !s[x].size()) return;
  vis[x] = 1;
  long long tmp = w[x] / (deg[x] + 1);
  s[0].insert((*s[x].begin()) + tmp);
  s[0].insert((*s[x].rbegin()) + tmp);
}
void change(int x, int u) {
  int y = a[x], z = a[y], p = a[z];
  del(a[x]), del(a[a[x]]), del(a[a[a[x]]]);
  del(u), del(a[u]), del(a[a[u]]);
  s[y].erase(s[y].find(f[x]));
  s[z].erase(s[z].find(f[y]));
  s[p].erase(s[p].find(f[z]));
  f[y] -= w[x] / (deg[x] + 1);
  f[y] -= w[y] - (w[y] / (deg[y] + 1)) * deg[y];
  f[y] += w[y] - (w[y] / deg[y]) * (deg[y] - 1);
  s[z].insert(f[y]);
  f[z] -= w[y] / (deg[y] + 1);
  f[z] += w[y] / deg[y];
  s[p].insert(f[z]);
  deg[y]--, deg[u]++;
  y = a[u], z = a[y];
  s[u].insert(f[x]);
  s[y].erase(s[y].find(f[u]));
  s[z].erase(s[z].find(f[y]));
  f[u] += w[x] / (deg[x] + 1);
  f[u] -= w[u] - (w[u] / deg[u]) * (deg[u] - 1);
  f[u] += w[u] - (w[u] / (deg[u] + 1)) * deg[u];
  s[y].insert(f[u]);
  f[y] -= w[u] / deg[u];
  f[y] += w[u] / (deg[u] + 1);
  s[z].insert(f[y]);
  add(a[x]), add(a[a[x]]), add(a[a[a[x]]]);
  add(u), add(a[u]), add(a[a[u]]);
  a[x] = u;
}
int main() {
  read(n), read(q);
  for (int i = 1; i <= n; i++) read(w[i]);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    deg[i]++, deg[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    long long tmp = w[i] / (deg[i] + 1);
    f[i] += w[i] - tmp * deg[i];
    f[a[i]] += tmp;
  }
  for (int i = 1; i <= n; i++) s[a[i]].insert(f[i]);
  for (int i = 1; i <= n; i++) add(i);
  for (int i = 1, opt, x, y; i <= q; i++) {
    read(opt);
    if (opt == 1) {
      read(x), read(y);
      change(x, y);
    }
    if (opt == 2) {
      read(x);
      printf("%lld\n", f[x] + w[a[x]] / (deg[a[x]] + 1));
    }
    if (opt == 3) printf("%lld %lld\n", (*s[0].begin()), (*s[0].rbegin()));
  }
  return 0;
}
