#include <bits/stdc++.h>
using namespace std;
long long n, q, b[100005], fa[100005], sz[100005], e[100005];
long long me[100005], songive[100005];
multiset<long long> all, son[100005];
inline long long read() {
  long long ret = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -ff;
    ch = getchar();
  }
  while (isdigit(ch)) {
    ret = (ret << 3) + (ret << 1) + ch - '0';
    ch = getchar();
  }
  return ret * ff;
}
void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
inline void addx(long long x) { son[fa[x]].insert(me[x] + songive[x]); }
inline void addall(long long x) {
  if (!son[x].size()) return;
  all.insert(*son[x].begin() + e[x]);
  all.insert(*--son[x].end() + e[x]);
}
inline void delx(long long x) {
  son[fa[x]].erase(son[fa[x]].find(me[x] + songive[x]));
}
inline void delall(long long x) {
  if (!son[x].size()) return;
  all.erase(all.find(*son[x].begin() + e[x]));
  all.erase(all.find(*--son[x].end() + e[x]));
}
signed main() {
  n = read(), q = read();
  for (long long i = 1; i <= n; i++) b[i] = read();
  for (long long i = 1; i <= n; i++) {
    fa[i] = read();
    sz[fa[i]]++;
  }
  for (long long i = 1; i <= n; i++) {
    e[i] = b[i] / (sz[i] + 2);
    me[i] = b[i] - e[i] * (sz[i] + 1);
    songive[fa[i]] += e[i];
  }
  for (long long i = 1; i <= n; i++) addx(i);
  for (long long i = 1; i <= n; i++) addall(i);
  while (q--) {
    long long opt = read();
    if (opt == 1) {
      long long x = read(), y = read();
      if (fa[x] == y) continue;
      delall(fa[x]), delall(fa[fa[x]]), delall(fa[fa[fa[x]]]);
      delx(x), delx(fa[x]), delx(fa[fa[x]]);
      songive[fa[x]] -= e[x], sz[fa[x]]--;
      songive[fa[fa[x]]] -= e[fa[x]];
      e[fa[x]] = b[fa[x]] / (sz[fa[x]] + 2);
      me[fa[x]] = b[fa[x]] - e[fa[x]] * (sz[fa[x]] + 1);
      songive[fa[fa[x]]] += e[fa[x]];
      addx(fa[x]), addx(fa[fa[x]]);
      addall(fa[x]), addall(fa[fa[x]]), addall(fa[fa[fa[x]]]);
      fa[x] = y;
      delall(fa[x]), delall(fa[fa[x]]), delall(fa[fa[fa[x]]]);
      delx(fa[x]), delx(fa[fa[x]]);
      songive[fa[x]] += e[x], sz[fa[x]]++;
      songive[fa[fa[x]]] -= e[fa[x]];
      e[fa[x]] = b[fa[x]] / (sz[fa[x]] + 2);
      me[fa[x]] = b[fa[x]] - e[fa[x]] * (sz[fa[x]] + 1);
      songive[fa[fa[x]]] += e[fa[x]];
      addx(x), addx(fa[x]), addx(fa[fa[x]]);
      addall(fa[x]), addall(fa[fa[x]]), addall(fa[fa[fa[x]]]);
    } else if (opt == 2) {
      long long x = read();
      write(me[x] + songive[x] + e[fa[x]]), puts("");
    } else {
      write(*all.begin()), putchar(' ');
      write(*--all.end()), puts("");
    }
  }
  return 0;
}
