#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
inline long long gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  long long sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
int n, q, d[maxn], f[maxn];
bool v[maxn];
long long a[maxn], t[maxn];
multiset<long long> s[maxn];
inline void del(int x) {
  if (v[x] && s[x].size()) {
    v[x] = 0;
    s[0].erase(s[0].find((*s[x].begin()) + t[x] / (d[x] + 1)));
    s[0].erase(s[0].find((*(--s[x].end())) + t[x] / (d[x] + 1)));
  }
}
inline void add(int x) {
  if (!v[x] && s[x].size()) {
    v[x] = 1;
    s[0].insert((*s[x].begin()) + t[x] / (d[x] + 1));
    s[0].insert((*(--s[x].end())) + t[x] / (d[x] + 1));
  }
}
inline void solve(int i, int j) {
  del(f[i]);
  del(f[f[i]]);
  del(f[f[f[i]]]);
  del(j);
  del(f[j]);
  del(f[f[j]]);
  s[f[i]].erase(s[f[i]].find(a[i]));
  s[f[f[i]]].erase(s[f[f[i]]].find(a[f[i]]));
  a[f[i]] -= t[i] / (d[i] + 1);
  a[f[i]] -= t[f[i]] - d[f[i]] * (t[f[i]] / (d[f[i]] + 1));
  a[f[i]] += t[f[i]] - (d[f[i]] - 1) * (t[f[i]] / d[f[i]]);
  s[f[f[i]]].insert(a[f[i]]);
  s[f[f[f[i]]]].erase(s[f[f[f[i]]]].find(a[f[f[i]]]));
  a[f[f[i]]] -= t[f[i]] / (d[f[i]] + 1);
  a[f[f[i]]] += t[f[i]] / d[f[i]];
  s[f[f[f[i]]]].insert(a[f[f[i]]]);
  --d[f[i]], ++d[j];
  s[j].insert(a[i]);
  s[f[j]].erase(s[f[j]].find(a[j]));
  a[j] += t[i] / (d[i] + 1);
  a[j] -= t[j] - (d[j] - 1) * (t[j] / d[j]);
  a[j] += t[j] - d[j] * (t[j] / (d[j] + 1));
  s[f[j]].insert(a[j]);
  s[f[f[j]]].erase(s[f[f[j]]].find(a[f[j]]));
  a[f[j]] -= t[j] / d[j];
  a[f[j]] += t[j] / (d[j] + 1);
  s[f[f[j]]].insert(a[f[j]]);
  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() {
  n = gi();
  q = gi();
  for (int i = 1; i <= n; ++i) t[i] = gi();
  for (int i = 1; i <= n; ++i) f[i] = gi();
  for (int i = 1; i <= n; ++i) ++d[i], ++d[f[i]];
  for (int i = 1; i <= n; ++i) {
    a[i] += t[i] - d[i] * (t[i] / (d[i] + 1));
    a[f[i]] += t[i] / (d[i] + 1);
  }
  for (int i = 1; i <= n; ++i) s[f[i]].insert(a[i]);
  for (int i = 1; i <= n; ++i) add(i);
  while (q--) {
    int tp, x, y;
    tp = gi();
    if (tp == 1)
      x = gi(), y = gi(), solve(x, y);
    else if (tp == 2)
      x = gi(), printf("%lld\n", a[x] + t[f[x]] / (d[f[x]] + 1));
    else
      printf("%lld %lld\n", *s[0].begin(), *(--s[0].end()));
  }
  return 0;
}
