#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool f = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = 1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return f ? -x : x;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
const int N = 300005;
int n, m, d[N], f[N];
long long b[N], e[N], l[N], r[N];
multiset<long long> S, s[N];
multiset<long long>::iterator it;
void calc(int x) {
  e[x] = b[x] / (d[x] + 2);
  l[x] = b[x] - (d[x] + 1) * e[x];
}
void add(int x) { s[f[x]].insert(l[x] + r[x]); }
void addall(int x) {
  if (!s[x].size()) return;
  it = s[x].begin();
  S.insert(*it + e[x]);
  it = s[x].end();
  --it;
  S.insert(*it + e[x]);
}
void del(int x) { s[f[x]].erase(s[f[x]].find(l[x] + r[x])); }
void delall(int x) {
  if (!s[x].size()) return;
  it = s[x].begin();
  S.erase(S.find(*it + e[x]));
  it = s[x].end();
  --it;
  S.erase(S.find(*it + e[x]));
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) b[i] = read();
  for (int i = 1; i <= n; i++) d[f[i] = read()]++;
  for (int i = 1; i <= n; i++) calc(i), r[f[i]] += e[i];
  for (int i = 1; i <= n; i++) add(i);
  for (int i = 1; i <= n; i++) addall(i);
  for (int i = 1; i <= m; i++) {
    int op = read();
    if (op == 1) {
      int x = read(), y = read();
      if (f[x] == y) continue;
      delall(f[x]);
      delall(f[f[x]]);
      delall(f[f[f[x]]]);
      del(x);
      del(f[x]);
      del(f[f[x]]);
      r[f[x]] -= e[x];
      d[f[x]]--;
      r[f[f[x]]] -= e[f[x]];
      calc(f[x]);
      r[f[f[x]]] += e[f[x]];
      add(f[x]);
      add(f[f[x]]);
      addall(f[x]);
      addall(f[f[x]]);
      addall(f[f[f[x]]]);
      f[x] = y;
      delall(f[x]);
      delall(f[f[x]]);
      delall(f[f[f[x]]]);
      del(f[x]);
      del(f[f[x]]);
      r[f[x]] += e[x];
      d[f[x]]++;
      r[f[f[x]]] -= e[f[x]];
      calc(f[x]);
      r[f[f[x]]] += e[f[x]];
      add(x);
      add(f[x]);
      add(f[f[x]]);
      addall(f[x]);
      addall(f[f[x]]);
      addall(f[f[f[x]]]);
    } else if (op == 2) {
      int x = read();
      printf("%lld\n", l[x] + r[x] + e[f[x]]);
    } else {
      it = S.begin();
      printf("%lld ", *it);
      it = S.end();
      --it;
      printf("%lld\n", *it);
    }
  }
  return 0;
}
