#include <bits/stdc++.h>
using namespace std;
vector<long long> t(100000 + 1, 0);
vector<set<pair<long long, int> > > x(100000 + 1, set<pair<long long, int> >());
vector<int> f(100000 + 1, 0), cnt(100000 + 1, 0);
set<pair<long long, int> > mi, ma;
vector<long long> y(100000 + 1, 0), last(100000 + 1, 0);
void U(int i, long long delta, int er, int ins) {
  if (!x[f[i]].empty()) {
    mi.erase(pair<long long, int>(
        x[f[i]].begin()->first + t[f[i]] / ((int)x[f[i]].size() + 2), f[i]));
    ma.erase(pair<long long, int>(
        x[f[i]].rbegin()->first + t[f[i]] / ((int)x[f[i]].size() + 2), f[i]));
  }
  if (er) x[f[i]].erase(pair<long long, int>(last[i], i));
  y[i] += delta;
  last[i] =
      t[i] - t[i] / ((int)x[i].size() + 2) * ((int)x[i].size() + 1) + y[i];
  if (ins) x[f[i]].insert(pair<long long, int>(last[i], i));
  if (!x[f[i]].empty()) {
    mi.insert(pair<long long, int>(
        x[f[i]].begin()->first + t[f[i]] / ((int)x[f[i]].size() + 2), f[i]));
    ma.insert(pair<long long, int>(
        x[f[i]].rbegin()->first + t[f[i]] / ((int)x[f[i]].size() + 2), f[i]));
  }
}
int main() {
  int n, q, i, j, c;
  cin >> n >> q;
  for (i = 1; i <= n; i++) cin >> t[i];
  for (i = 1; i <= n; i++) {
    cin >> f[i];
    cnt[f[i]]++;
  }
  for (i = 1; i <= n; i++) {
    y[f[i]] += t[i] / (cnt[i] + 2);
  }
  for (i = 1; i <= n; i++) {
    last[i] = t[i] - t[i] / (cnt[i] + 2) * (cnt[i] + 1) + y[i];
    x[f[i]].insert(pair<long long, int>(last[i], i));
  }
  for (i = 1; i <= n; i++) {
    if (!x[i].empty()) {
      mi.insert(pair<long long, int>(
          x[i].begin()->first + t[i] / ((int)x[i].size() + 2), i));
      ma.insert(pair<long long, int>(
          x[i].rbegin()->first + t[i] / ((int)x[i].size() + 2), i));
    }
  }
  while (q--) {
    cin >> c;
    if (c == 1) {
      cin >> i >> j;
      U(i, 0, 1, 0);
      U(f[i], -t[i] / ((int)x[i].size() + 2), 1, 1);
      U(f[f[i]],
        t[f[i]] / ((int)x[f[i]].size() + 2) -
            t[f[i]] / ((int)x[f[i]].size() + 3),
        1, 1);
      f[i] = j;
      U(i, 0, 0, 1);
      U(f[i], t[i] / ((int)x[i].size() + 2), 1, 1);
      U(f[f[i]],
        t[f[i]] / ((int)x[f[i]].size() + 2) -
            t[f[i]] / ((int)x[f[i]].size() + 1),
        1, 1);
    }
    if (c == 2) {
      cin >> i;
      cout << last[i] + t[f[i]] / (x[f[i]].size() + 2) << endl;
    }
    if (c == 3) {
      cout << mi.begin()->first << ' ' << ma.rbegin()->first << endl;
    }
  }
  return 0;
}
