#include <bits/stdc++.h>
inline long long inp() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  long long sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
long long a[100010], b[100010], c[100010], d[100010], e[100010];
std::multiset<long long> min_num, max_num, s[100010];
inline void del(int x) {
  if (s[x].empty()) return;
  min_num.erase(min_num.find(*s[x].begin() + e[x]));
  max_num.erase(max_num.find(*s[x].rbegin() + e[x]));
}
inline void add(int x) {
  if (s[x].empty()) return;
  min_num.insert(*s[x].begin() + e[x]);
  max_num.insert(*s[x].rbegin() + e[x]);
}
inline void print(int x) {
  printf("c[%d] = %I64d, e[%d] = %I64d, s[%d] = {", x, c[x], x, e[x], x);
  for (std::set<long long>::iterator it = s[x].begin(); it != s[x].end();
       it++) {
    printf("%I64d ", (*it));
  }
  printf("}\n");
}
int main() {
  int n = inp();
  int q = inp();
  for (int i = 1; i <= n; i++) {
    b[i] = inp();
    d[i] = 2;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = inp();
    d[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    e[i] = b[i] / d[i];
    c[i] = b[i] % d[i] + e[i];
  }
  for (int i = 1; i <= n; i++) c[a[i]] += e[i];
  for (int i = 1; i <= n; i++) s[a[i]].insert(c[i]);
  for (int i = 1; i <= n; i++) add(i);
  for (int i = 1; i <= q; i++) {
    int type = inp();
    if (type == 1) {
      int u = inp();
      int v = inp();
      int f1 = a[u];
      int f2 = a[a[u]];
      int f3 = a[a[a[u]]];
      del(f1);
      del(f2);
      del(f3);
      s[f1].erase(s[f1].find(c[u]));
      s[f2].erase(s[f2].find(c[f1]));
      s[f3].erase(s[f3].find(c[f2]));
      c[f2] -= e[f1];
      c[f1] -= (b[f1] % d[f1]) + e[u] + e[f1];
      d[f1]--;
      e[f1] = b[f1] / d[f1];
      c[f1] += (b[f1] % d[f1]) + e[f1];
      c[f2] += e[f1];
      s[f2].insert(c[f1]);
      s[f3].insert(c[f2]);
      add(f1);
      add(f2);
      add(f3);
      a[u] = v;
      f1 = a[u];
      f2 = a[a[u]];
      f3 = a[a[a[u]]];
      del(f1);
      del(f2);
      del(f3);
      s[f2].erase(s[f2].find(c[f1]));
      s[f3].erase(s[f3].find(c[f2]));
      c[f2] -= e[f1];
      c[f1] -= (b[f1] % d[f1]) + e[f1];
      d[f1]++;
      e[f1] = b[f1] / d[f1];
      c[f1] += (b[f1] % d[f1]) + e[u] + e[f1];
      c[f2] += e[f1];
      s[f1].insert(c[u]);
      s[f2].insert(c[f1]);
      s[f3].insert(c[f2]);
      add(f1);
      add(f2);
      add(f3);
    } else if (type == 2) {
      int x = inp();
      printf("%I64d\n", c[x] + e[a[x]]);
    } else {
      printf("%I64d %I64d\n", (*min_num.begin()), (*max_num.rbegin()));
    }
  }
}
