#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
inline long long read() {
  long long x = 0;
  int c = getchar(), f = 0;
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  return f ? -x : x;
}
inline void write(long long x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int n, Q, a[N];
long long b[N], e[N], s[N], d[N];
struct HEAP {
  priority_queue<long long> ADD, DEL, add[N], del[N];
  long long get() {
    while (DEL.size() && DEL.top() == ADD.top()) DEL.pop(), ADD.pop();
    return ADD.top();
  }
  void Del(int& x, long long k, long long c) {
    k *= c;
    del[x].push(k);
    if (del[x].top() == add[x].top()) {
      DEL.push(add[x].top() + c * e[x]);
      while (del[x].size() && del[x].top() == add[x].top())
        del[x].pop(), add[x].pop();
      if (add[x].size()) ADD.push(add[x].top() + c * e[x]);
    }
  }
  void Add(int& x, long long k, long long c) {
    k *= c;
    if (!add[x].size() || k > add[x].top()) {
      if (add[x].size()) DEL.push(add[x].top() + c * e[x]);
      add[x].push(k);
      while (del[x].size() && del[x].top() == add[x].top())
        del[x].pop(), add[x].pop();
      ADD.push(add[x].top() + c * e[x]);
    } else
      add[x].push(k);
  }
  void fuck(int& x, long long E, long long c) {
    if (!add[x].size()) return;
    DEL.push(add[x].top() + c * e[x]);
    ADD.push(add[x].top() + c * E);
  }
} B, S;
void solve() {
  long long k;
  int x;
  k = S.get();
  write(-k);
  putchar(' ');
  k = B.get();
  write(k);
  putchar('\n');
}
void change(int x, int T) {
  int y, z;
  y = a[x];
  z = a[y];
  B.Del(a[x], s[x], 1);
  S.Del(a[x], s[x], -1);
  B.Del(a[y], s[y], 1);
  S.Del(a[y], s[y], -1);
  s[y] -= e[y] + e[x] + b[y] % d[y];
  B.Del(a[z], s[z], 1);
  S.Del(a[z], s[z], -1);
  s[z] -= e[y];
  d[y]--;
  B.fuck(y, b[y] / d[y], 1);
  S.fuck(y, b[y] / d[y], -1);
  e[y] = b[y] / d[y];
  s[y] += e[y] + b[y] % d[y];
  B.Add(a[y], s[y], 1);
  S.Add(a[y], s[y], -1);
  s[z] += e[y];
  B.Add(a[z], s[z], 1);
  S.Add(a[z], s[z], -1);
  a[x] = T;
  y = a[x];
  z = a[y];
  B.Del(a[y], s[y], 1);
  S.Del(a[y], s[y], -1);
  s[y] -= e[y] + b[y] % d[y];
  B.Del(a[z], s[z], 1);
  S.Del(a[z], s[z], -1);
  s[z] -= e[y];
  d[y]++;
  B.fuck(y, b[y] / d[y], 1);
  S.fuck(y, b[y] / d[y], -1);
  e[y] = b[y] / d[y];
  s[y] += e[y] + e[x] + b[y] % d[y];
  B.Add(a[y], s[y], 1);
  S.Add(a[y], s[y], -1);
  s[z] += e[y];
  B.Add(a[z], s[z], 1);
  S.Add(a[z], s[z], -1);
  B.Add(a[x], s[x], 1);
  S.Add(a[x], s[x], -1);
}
int main() {
  n = read();
  Q = read();
  int i;
  for (i = 1; i <= n; i++) b[i] = read(), d[i] = 1;
  for (i = 1; i <= n; i++) a[i] = read(), d[a[i]]++, d[i]++;
  for (i = 1; i <= n; i++) e[i] = b[i] / d[i], s[i] = b[i] % d[i] + e[i];
  for (i = 1; i <= n; i++) s[a[i]] += e[i];
  for (i = 1; i <= n; i++) B.Add(a[i], s[i], 1), S.Add(a[i], s[i], -1);
  for (int o, x; Q--;) {
    o = read();
    if (o == 2) {
      x = read();
      write(s[x] + e[a[x]]);
      putchar('\n');
    } else if (o == 3)
      solve();
    else
      x = read(), change(x, read());
  }
  return 0;
}
