#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
long long n, m;
long long b[maxn], f[maxn], g[maxn], num[maxn], e[maxn], gg[maxn];
multiset<long long> son[maxn], ans;
multiset<long long>::iterator it;
inline void update_ans(long long x) {
  if (son[x].empty()) return;
  it = son[x].begin();
  ans.insert(*it + e[x]);
  it = --son[x].end();
  if (it != son[x].begin()) ans.insert(*it + e[x]);
}
inline void insert(long long x) { son[f[x]].insert(g[x] + gg[x]); }
inline void calc(long long x) {
  e[x] = b[x] / (num[x] + 2);
  g[x] = b[x] - (num[x] + 1) * e[x];
}
inline void del(long long x) { son[f[x]].erase(son[f[x]].find(g[x] + gg[x])); }
inline void del_ans(long long x) {
  if (son[x].empty()) return;
  it = son[x].begin();
  ans.erase(ans.find(*it + e[x]));
  it = --son[x].end();
  if (it != son[x].begin()) ans.erase(ans.find(*it + e[x]));
}
inline void cut(long long x) {
  del_ans(f[x]);
  del_ans(f[f[x]]);
  del_ans(f[f[f[x]]]);
  del(x);
  del(f[x]);
  del(f[f[x]]);
  gg[f[f[x]]] -= e[f[x]];
  gg[f[x]] -= e[x];
  num[f[x]]--;
  calc(f[x]);
  gg[f[f[x]]] += e[f[x]];
  insert(f[x]);
  insert(f[f[x]]);
  update_ans(f[x]);
  update_ans(f[f[x]]);
  update_ans(f[f[f[x]]]);
}
inline void link(long long x, long long y) {
  f[x] = y;
  num[y]++;
  del_ans(y);
  del_ans(f[y]);
  del_ans(f[f[y]]);
  del(y);
  del(f[y]);
  gg[f[y]] -= e[y];
  gg[y] += e[x];
  calc(y);
  gg[f[y]] += e[y];
  insert(x);
  insert(y);
  insert(f[y]);
  update_ans(y);
  update_ans(f[y]);
  update_ans(f[f[y]]);
}
signed main() {
  long long i;
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &b[i]);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &f[i]);
    num[f[i]]++;
  }
  for (i = 1; i <= n; i++) calc(i), gg[f[i]] += e[i];
  for (i = 1; i <= n; i++) insert(i);
  for (i = 1; i <= n; i++) update_ans(i);
  for (i = 1; i <= m; i++) {
    long long op, x, y;
    scanf("%lld", &op);
    if (op == 1) {
      scanf("%lld%lld", &x, &y);
      cut(x);
      link(x, y);
    } else if (op == 2) {
      scanf("%lld", &x);
      printf("%lld\n", g[x] + gg[x] + e[f[x]]);
    } else {
      it = ans.begin();
      printf("%lld ", *it);
      it = --ans.end();
      printf("%lld\n", *it);
    }
  }
  return 0;
}
