#include <bits/stdc++.h>
template <class T>
inline T read() {
  register T data = 0, w = 1;
  register char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (isdigit(ch)) data = data * 10 + ch - '0', ch = getchar();
  return data * w;
}
template <class T>
inline T read(register T& x) {
  return x = read<T>();
}
using namespace std;
const int N = 1e5 + 1;
int n, q, num[N], f[N];
long long t[N], val[N], dev[N], add[N];
multiset<long long> Ans, Son[N];
multiset<long long>::iterator it;
void rev(int x) {
  if (Son[x].empty()) return;
  it = Son[x].begin(), Ans.insert(*it + add[x]);
  it = Son[x].end(), --it, Ans.insert(*it + add[x]);
}
void del(int x) {
  if (Son[x].empty()) return;
  it = Son[x].begin(), Ans.erase(Ans.find(*it + add[x]));
  it = Son[x].end(), --it, Ans.erase(Ans.find(*it + add[x]));
}
void Rev(int x) { Son[f[x]].insert(val[x] + dev[x]); }
void Del(int x) { Son[f[x]].erase(Son[f[x]].find(val[x] + dev[x])); }
void calc(int x) {
  add[x] = t[x] / (num[x] + 2);
  val[x] = t[x] - (num[x] + 1) * add[x];
}
int main() {
  read(n), read(q);
  for (int i = 1; i <= n; ++i) read(t[i]);
  for (int i = 1; i <= n; ++i) ++num[read(f[i])];
  for (int i = 1; i <= n; ++i) {
    calc(i);
    dev[f[i]] += add[i];
  }
  for (int i = 1; i <= n; ++i) Rev(i);
  for (int i = 1; i <= n; ++i) rev(i);
  for (int i = 1, o, x, y; i <= q; ++i) {
    if (read(o) == 1) {
      read(x), read(y);
      if (f[x] == y) continue;
      del(f[x]), del(f[f[x]]), del(f[f[f[x]]]);
      Del(x), Del(f[x]), Del(f[f[x]]);
      dev[f[x]] -= add[x], --num[f[x]];
      dev[f[f[x]]] -= add[f[x]];
      calc(f[x]);
      dev[f[f[x]]] += add[f[x]];
      Rev(f[x]), Rev(f[f[x]]);
      rev(f[x]), rev(f[f[x]]), rev(f[f[f[x]]]);
      f[x] = y;
      del(f[x]), del(f[f[x]]), del(f[f[f[x]]]);
      Del(f[x]), Del(f[f[x]]);
      dev[f[x]] += add[x], ++num[f[x]];
      dev[f[f[x]]] -= add[f[x]];
      calc(f[x]);
      dev[f[f[x]]] += add[f[x]];
      Rev(x), Rev(f[x]), Rev(f[f[x]]);
      rev(f[x]), rev(f[f[x]]), rev(f[f[f[x]]]);
    } else if (o == 2) {
      read(x);
      printf("%I64d\n", dev[x] + val[x] + add[f[x]]);
    } else {
      it = Ans.begin(), printf("%I64d ", *it);
      it = Ans.end(), --it, printf("%I64d\n", *it);
    }
  }
  return 0;
}
