#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void write(long long x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 100050;
int n, q, f[N], d[N];
long long a[N], t[N], v[N];
multiset<long long> s[N];
bool vis[N];
inline void dev(int x) {
  if (vis[x] && s[x].size()) {
    vis[x] = 0, s[0].erase(s[0].find(v[x] + (*s[x].begin()))),
    s[0].erase(s[0].find(v[x] + (*--s[x].end())));
  }
}
inline void add(int x) {
  if (!vis[x] && s[x].size()) {
    vis[x] = 1, s[0].insert(v[x] + (*s[x].begin())),
    s[0].insert(v[x] + (*--s[x].end()));
  }
}
inline void modify(int i, int j) {
  if (j == f[i]) return;
  int x, y, z;
  dev(f[i]), dev(f[f[i]]), dev(f[f[f[i]]]), dev(j), dev(f[j]), dev(f[f[j]]);
  x = f[i], y = f[x], z = f[y];
  s[z].erase(s[z].find(a[y])), s[y].erase(s[y].find(a[x])),
      s[x].erase(s[x].find(a[i]));
  a[y] -= v[x];
  a[x] -= t[x] - d[x] * v[x], a[x] -= v[i];
  --d[x], v[x] = t[x] / (d[x] + 1);
  a[x] += t[x] - d[x] * v[x];
  a[y] += v[x];
  s[z].insert(a[y]), s[y].insert(a[x]);
  x = j, y = f[x], z = f[y];
  s[z].erase(s[z].find(a[y])), s[y].erase(s[y].find(a[x]));
  a[y] -= v[x];
  a[x] -= t[x] - d[x] * v[x], a[x] += v[i];
  ++d[x], v[x] = t[x] / (d[x] + 1);
  a[x] += t[x] - d[x] * v[x];
  a[y] += v[x];
  s[z].insert(a[y]), s[y].insert(a[x]), s[x].insert(a[i]);
  add(f[i]), add(f[f[i]]), add(f[f[f[i]]]), add(j), add(f[j]), add(f[f[j]]);
  f[i] = j;
}
int main() {
  int i, op, x, y;
  read(n), read(q);
  for (i = 1; i <= n; ++i) read(t[i]), d[i] = 1;
  for (i = 1; i <= n; ++i) read(f[i]), ++d[f[i]];
  for (i = 1; i <= n; ++i)
    v[i] = t[i] / (d[i] + 1), a[f[i]] += v[i], a[i] += t[i] - v[i] * d[i];
  for (i = 1; i <= n; ++i) s[f[i]].insert(a[i]);
  for (i = 1; i <= n; ++i) add(i);
  while (q--) {
    read(op);
    if (op == 1)
      read(x), read(y), modify(x, y);
    else if (op == 2)
      read(x), write(a[x] + v[f[x]]), putchar('\n');
    else
      write(*s[0].begin()), putchar(' '), write(*(--s[0].end())), putchar('\n');
  }
  return 0;
}
