#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int d[N], f[N], n, Q, opt, x;
long long sum[N], a[N];
set<pair<long long, int> > s[N], S;
long long getans(int x) {
  return sum[x] + a[x] / d[x] + a[x] % d[x] + a[f[x]] / d[f[x]];
}
long long cal(int x) { return sum[x] + a[x] / d[x] + a[x] % d[x]; }
void add(int x) {
  if (!s[x].size()) return;
  pair<long long, int> t = *s[x].begin();
  S.insert(make_pair(getans(t.second), t.second));
  t = *s[x].rbegin();
  S.insert(make_pair(getans(t.second), t.second));
}
void del(int x) {
  if (!s[x].size()) return;
  pair<long long, int> t = *s[x].begin();
  S.erase(make_pair(getans(t.second), t.second));
  t = *(--s[x].end());
  S.erase(make_pair(getans(t.second), t.second));
}
void Del(int x, int y) {
  int z = f[y], zz = f[z];
  del(z);
  s[z].erase(make_pair(cal(y), y));
  del(zz);
  s[zz].erase(make_pair(cal(z), z));
  sum[z] -= a[y] / d[y];
  del(y);
  s[y].erase(make_pair(cal(x), x));
  sum[y] -= a[x] / d[x];
  d[y]--;
  add(y);
  sum[z] += a[y] / d[y];
  s[z].insert(make_pair(cal(y), y));
  add(z);
  s[zz].insert(make_pair(cal(z), z));
  add(zz);
}
void Add(int x, int y) {
  int z = f[y], zz = f[z];
  del(zz);
  s[zz].erase(make_pair(cal(z), z));
  del(z);
  s[z].erase(make_pair(cal(y), y));
  sum[z] -= a[y] / d[y];
  del(y);
  s[y].insert(make_pair(cal(x), x));
  sum[y] += a[x] / d[x];
  d[y]++;
  add(y);
  sum[z] += a[y] / d[y];
  s[z].insert(make_pair(cal(y), y));
  add(z);
  s[zz].insert(make_pair(cal(z), z));
  add(zz);
}
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++) d[i] = 2;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &f[i]);
    d[f[i]]++;
  }
  for (int i = 1; i <= n; i++) sum[f[i]] += a[i] / d[i];
  for (int i = 1; i <= n; i++) s[f[i]].insert(make_pair(cal(i), i));
  for (int i = 1; i <= n; i++) add(i);
  while (Q--) {
    scanf("%d", &opt);
    if (opt == 1) {
      scanf("%d", &x);
      Del(x, f[x]);
      scanf("%d", &f[x]);
      Add(x, f[x]);
    } else if (opt == 2) {
      scanf("%d", &x);
      printf("%lld\n", getans(x));
    } else {
      printf("%lld %lld\n", (*S.begin()).first, (*(--S.end())).first);
    }
  }
}
