#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool checkMax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T, typename... Args>
inline void checkMax(T &a, const Args... arg) {
  checkMax(a, max(arg...));
}
template <class T>
inline bool checkMin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename... Args>
inline void checkMin(T &a, const Args... arg) {
  checkMin(a, min(arg...));
}
const int INF = 0x3f3f3f3f;
const long long llINF = 1e18;
const int MAXN = 1e5 + 5;
int n, Q;
int f[MAXN], num[MAXN];
long long t[MAXN], sum[MAXN];
multiset<long long> s[MAXN], S;
long long calcself(int i) {
  return t[i] - (t[i] / (num[i] + 2)) * (num[i] + 1);
}
long long calcson(int i) { return t[i] / (num[i] + 2); }
void addmax(int i) {
  if (s[i].empty()) return;
  S.insert(*(--s[i].end()) + calcson(i));
}
void addmin(int i) {
  if (s[i].empty()) return;
  S.insert(*s[i].begin() + calcson(i));
}
void delmax(int i) {
  if (s[i].empty()) return;
  S.erase(S.find(*(--s[i].end()) + calcson(i)));
}
void delmin(int i) {
  if (s[i].empty()) return;
  S.erase(S.find(*s[i].begin() + calcson(i)));
}
void solve(int x, int y) {
  set<int> tmp = {x, f[x], f[f[x]], y, f[y]}, need, fneed;
  for (int i : tmp)
    if (i) need.insert(i);
  fneed = need;
  for (int i : need)
    if (f[i]) fneed.insert(f[i]);
  for (int i : fneed) delmax(i), delmin(i);
  for (int i : need) s[f[i]].erase(s[f[i]].find(sum[i]));
  for (int i : need) {
    sum[i] -= calcself(i);
    for (int j : need)
      if (f[j] == i) sum[i] -= calcson(j);
  }
  num[f[x]] -= 1;
  f[x] = y;
  num[y] += 1;
  for (int i : need) {
    sum[i] += calcself(i);
    for (int j : need)
      if (f[j] == i) sum[i] += calcson(j);
  }
  for (int i : need) s[f[i]].insert(sum[i]);
  for (int i : fneed) addmax(i), addmin(i);
}
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; i++) scanf("%lld", &t[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &f[i]), num[f[i]] += 1;
  for (int i = 1; i <= n; i++) sum[i] += calcself(i), sum[f[i]] += calcson(i);
  for (int i = 1; i <= n; i++) s[f[i]].insert(sum[i]);
  for (int i = 1; i <= n; i++) addmax(i), addmin(i);
  while (Q--) {
    int op, x, y;
    scanf("%d", &op);
    if (op == 1)
      scanf("%d%d", &x, &y), solve(x, y);
    else if (op == 2)
      scanf("%d", &x), printf("%lld\n", sum[x] + calcson(f[x]));
    else if (op == 3)
      printf("%lld %lld\n", *S.begin(), *(--S.end()));
  }
  return 0;
}
