#include <bits/stdc++.h>
using namespace std;
const int N = 100035;
const int inf = 1000000009;
long long rd() {
  char c = getchar();
  long long t = 0, f = 1;
  while (!isdigit(c)) f = (c == '-') ? -1 : 1, c = getchar();
  while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
  return t * f;
}
void wt(int x) {
  if (x < 0)
    putchar('-'), wt(-x);
  else {
    if (x > 9) wt(x / 10);
    putchar(x % 10 + 48);
  }
}
set<pair<long long, int> > mn, mx, s[N];
long long a[N], b[N], d[N], e[N], f[N], n, Q, now, opt, x, y, ax, Ax, Aax, ay,
    Ay;
void debug() {
  printf("%I64d ", (*mn.begin()).first);
  printf("%I64d\n", (*mx.rbegin()).first);
}
void del(int ax, int x, int flg) {
  if (s[ax].size()) mn.erase(make_pair((*s[ax].begin()).first + e[ax], ax));
  if (s[ax].size()) mx.erase(make_pair((*s[ax].rbegin()).first + e[ax], ax));
  if (flg) s[ax].erase(make_pair(f[x], x));
}
void ins(int ax, int x) {
  s[ax].insert(make_pair(f[x], x));
  mn.insert(make_pair((*s[ax].begin()).first + e[ax], ax));
  mx.insert(make_pair((*s[ax].rbegin()).first + e[ax], ax));
}
int main() {
  n = rd(), Q = rd();
  for (int i = ((int)1); i <= ((int)n); i++) b[i] = rd(), d[i] = 1;
  for (int i = ((int)1); i <= ((int)n); i++) d[i]++, d[a[i] = rd()]++;
  for (int i = ((int)1); i <= ((int)n); i++) {
    e[i] = b[i] / d[i];
    f[i] += e[i], f[a[i]] += e[i];
  }
  for (int i = ((int)1); i <= ((int)n); i++) f[i] += b[i] % d[i];
  for (int i = ((int)1); i <= ((int)n); i++) s[a[i]].insert(make_pair(f[i], i));
  for (int i = ((int)1); i <= ((int)n); i++)
    if (s[i].size()) {
      mn.insert(make_pair((*s[i].begin()).first + e[i], i));
      mx.insert(make_pair((*s[i].rbegin()).first + e[i], i));
    }
  for (now = 1; now <= Q; now++) {
    opt = rd();
    if (opt == 1) {
      x = rd(), y = rd();
      ax = a[x], Ax = a[a[x]], Aax = a[a[a[x]]];
      ay = a[y], Ay = a[a[y]];
      del(ax, x, 1);
      del(Ax, ax, 1);
      del(Aax, Ax, 1);
      f[Ax] -= e[ax];
      f[ax] -= b[ax] % d[ax] + e[x] + e[ax], d[ax]--;
      e[ax] = b[ax] / d[ax], f[ax] += b[ax] % d[ax] + e[ax];
      f[Ax] += e[ax];
      if (s[ax].size())
        mn.insert(make_pair((*s[ax].begin()).first + e[ax], ax));
      if (s[ax].size())
        mx.insert(make_pair((*s[ax].rbegin()).first + e[ax], ax));
      ins(Ax, ax);
      ins(Aax, Ax);
      del(y, x, 0);
      del(ay, y, 1);
      del(Ay, ay, 1);
      f[ay] -= e[y];
      f[y] -= b[y] % d[y] + e[y], d[y]++;
      e[y] = b[y] / d[y], f[y] += b[y] % d[y] + e[y] + e[x];
      f[ay] += e[y];
      ins(y, x);
      ins(ay, y);
      ins(Ay, ay);
      a[x] = y;
    } else if (opt == 2)
      x = rd(), printf("%I64d\n", f[x] + e[a[x]]);
    else {
      debug();
    }
  }
  return 0;
}
