#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
set<long long>::iterator it;
multiset<long long> son[N], res;
int d[N], a[N];
long long b[N], c[N], f[N], e[N];
long long read() {
  long long A;
  bool K;
  char C;
  C = A = K = 0;
  while (C < '0' || C > '9') K |= C == '-', C = getchar();
  while (C > '/' && C < ':') A = (A << 3) + (A << 1) + (C ^ 48), C = getchar();
  return (K ? -A : A);
}
void write(long long X) {
  if (X < 0) putchar('-'), X = -X;
  if (X > 9) write(X / 10);
  putchar(X % 10 + 48);
}
void ins1(int x) {
  if (son[x].empty()) return;
  res.insert(*son[x].begin() + e[x]);
  it = son[x].end();
  res.insert(*--it + e[x]);
}
void del1(int x) {
  if (son[x].empty()) return;
  res.erase(res.find(*son[x].begin() + e[x]));
  it = son[x].end();
  res.erase(res.find(*--it + e[x]));
}
inline void ins2(int x) { son[a[x]].insert(c[x] + f[x]); }
inline void del2(int x) { son[a[x]].erase(son[a[x]].find(c[x] + f[x])); }
inline void modern(int x) {
  e[x] = b[x] / (d[x] + 2);
  c[x] = b[x] - (d[x] + 1) * e[x];
}
int main() {
  int i, n, q, opt, v1, v2;
  n = read(), q = read();
  for (i = 1; i <= n; i++) b[i] = read();
  for (i = 1; i <= n; i++) a[i] = read(), d[a[i]]++;
  for (i = 1; i <= n; i++) modern(i), f[a[i]] += e[i];
  for (i = 1; i <= n; i++) ins2(i);
  for (i = 1; i <= n; i++) ins1(i);
  for (i = 1; i <= q; i++) {
    opt = read();
    if (opt == 1) {
      v1 = read(), v2 = read();
      if (a[v1] == v2) continue;
      del1(a[v1]), del1(a[a[v1]]), del1(a[a[a[v1]]]);
      del2(v1), del2(a[v1]), del2(a[a[v1]]);
      d[a[v1]]--;
      f[a[v1]] -= e[v1];
      f[a[a[v1]]] -= e[a[v1]];
      modern(a[v1]);
      f[a[a[v1]]] += e[a[v1]];
      ins2(a[v1]), ins2(a[a[v1]]);
      ins1(a[v1]), ins1(a[a[v1]]), ins1(a[a[a[v1]]]);
      a[v1] = v2;
      del1(a[v1]), del1(a[a[v1]]), del1(a[a[a[v1]]]);
      del2(a[v1]), del2(a[a[v1]]);
      f[a[v1]] += e[v1];
      d[a[v1]]++;
      f[a[a[v1]]] -= e[a[v1]];
      modern(a[v1]);
      f[a[a[v1]]] += e[a[v1]];
      ins2(v1), ins2(a[v1]), ins2(a[a[v1]]);
      ins1(a[v1]), ins1(a[a[v1]]), ins1(a[a[a[v1]]]);
      continue;
    }
    if (opt == 2) {
      v1 = read();
      write(f[v1] + c[v1] + e[a[v1]]);
      putchar('\n');
      continue;
    }
    write(*res.begin());
    putchar(' ');
    it = res.end();
    write(*--it);
    putchar('\n');
  }
  return 0;
}
