#include <bits/stdc++.h>
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, ff = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * ff;
}
void write(long long aa) {
  if (aa < 0) putchar('-'), aa = -aa;
  if (aa > 9) write(aa / 10);
  putchar(aa % 10 + '0');
  return;
}
long long n, Q;
long long B[100005], A[100005];
struct node {
  long long D, E, F;
  multiset<long long> son;
} a[100005];
multiset<long long> Smn, Smx;
multiset<long long>::iterator it;
void del(long long aa) {
  if (a[aa].son.begin() == a[aa].son.end()) return;
  it = a[aa].son.begin();
  it = Smn.lower_bound((*it) + a[aa].E);
  Smn.erase(it);
  it = a[aa].son.end();
  it--;
  it = Smx.lower_bound((*it) + a[aa].E);
  Smx.erase(it);
  return;
}
void add(long long aa) {
  if (a[aa].son.begin() == a[aa].son.end()) return;
  it = a[aa].son.begin();
  Smn.insert((*it) + a[aa].E);
  it = a[aa].son.end(), it--;
  Smx.insert((*it) + a[aa].E);
  return;
}
int main() {
  n = read();
  Q = read();
  for (long long i = 1; i <= n; ++i) B[i] = read(), a[i].F = B[i], a[i].D = 1;
  for (long long i = 1; i <= n; ++i) A[i] = read(), a[A[i]].D++, a[i].D++;
  for (long long i = 1; i <= n; ++i)
    a[i].E = B[i] / a[i].D, a[i].F -= a[i].E * a[i].D, a[A[i]].F += a[i].E,
    a[i].F += a[i].E;
  for (long long i = 1; i <= n; ++i) a[A[i]].son.insert(a[i].F);
  for (long long i = 1; i <= n; ++i) add(i);
  while (Q--) {
    long long ff = read();
    if (ff == 1) {
      long long x = read(), y = read();
      del(A[x]);
      it = a[A[x]].son.lower_bound(a[x].F);
      a[A[x]].son.erase(it);
      del(A[A[A[x]]]);
      it = a[A[A[A[x]]]].son.lower_bound(a[A[A[x]]].F);
      a[A[A[A[x]]]].son.erase(it);
      del(A[A[x]]);
      it = a[A[A[x]]].son.lower_bound(a[A[x]].F);
      a[A[A[x]]].son.erase(it);
      a[A[A[x]]].F -= a[A[x]].E;
      a[A[x]].F -= a[A[x]].E;
      a[A[x]].F += a[A[x]].E * a[A[x]].D;
      a[A[x]].F -= a[x].E;
      a[A[x]].D--;
      a[A[x]].E = B[A[x]] / a[A[x]].D;
      a[A[x]].F -= a[A[x]].E * a[A[x]].D;
      a[A[x]].F += a[A[x]].E;
      a[A[A[x]]].F += a[A[x]].E;
      a[A[A[x]]].son.insert(a[A[x]].F);
      add(A[A[x]]);
      a[A[A[A[x]]]].son.insert(a[A[A[x]]].F);
      add(A[A[A[x]]]);
      add(A[x]);
      A[x] = y;
      del(A[x]);
      a[A[x]].son.insert(a[x].F);
      del(A[A[A[x]]]);
      it = a[A[A[A[x]]]].son.lower_bound(a[A[A[x]]].F);
      a[A[A[A[x]]]].son.erase(it);
      del(A[A[x]]);
      it = a[A[A[x]]].son.lower_bound(a[A[x]].F);
      a[A[A[x]]].son.erase(it);
      a[A[A[x]]].F -= a[A[x]].E;
      a[A[x]].F -= a[A[x]].E;
      a[A[x]].F += a[A[x]].E * a[A[x]].D;
      a[A[x]].D++;
      a[A[x]].E = B[A[x]] / a[A[x]].D;
      a[A[x]].F += a[x].E;
      a[A[x]].F -= a[A[x]].E * a[A[x]].D;
      a[A[x]].F += a[A[x]].E;
      a[A[A[x]]].F += a[A[x]].E;
      a[A[A[x]]].son.insert(a[A[x]].F);
      add(A[A[x]]);
      a[A[A[A[x]]]].son.insert(a[A[A[x]]].F);
      add(A[A[A[x]]]);
      add(A[x]);
    } else if (ff == 2) {
      long long x = read();
      write(a[x].F + a[A[x]].E), puts("");
    } else if (ff == 3) {
      it = Smx.end();
      it--;
      write(*Smn.begin());
      putchar(' ');
      write(*it);
      puts("");
    }
  }
  return 0;
}
