#include <bits/stdc++.h>
const int maxn = 2e5 + 7;
using namespace std;
multiset<long long> ss1, ss2[maxn];
int fa[maxn];
int flag[maxn], flag1[maxn];
long long sum[maxn], w[maxn], du[maxn];
long long getsum(int x) { return w[x] / (du[x] + 1); }
long long getsum1(int x) {
  return sum[x] + w[x] - du[x] * (w[x] / (du[x] + 1)) + getsum(fa[x]);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    du[i]++;
    scanf("%lld", &w[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &fa[i]);
    du[fa[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    int num = fa[i];
    long long sum0 = w[i] / (du[i] + 1);
    sum[fa[i]] += sum0;
  }
  for (int i = 1; i <= n; i++) {
    long long sum0 = w[fa[i]] / (du[fa[i]] + 1);
    ss2[fa[i]].insert(getsum1(i) - sum0);
  }
  long long mins, maxs;
  for (int i = 1; i <= n; i++) {
    if (du[i] == 1) continue;
    if (ss2[i].size() > 1) {
      mins = *ss2[i].begin();
      maxs = *(--ss2[i].end());
      long long sum0 = w[i] / (du[i] + 1);
      ss1.insert(mins + sum0);
      ss1.insert(maxs + sum0);
    } else if (ss2[i].size()) {
      mins = *ss2[i].begin();
      long long sum0 = w[i] / (du[i] + 1);
      ss1.insert(mins + sum0);
    }
  }
  int s, u, v;
  for (int i = 1; i <= m; i++) {
    multiset<long long>::iterator pos, pos1;
    scanf("%d", &s);
    if (s == 1) {
      scanf("%d%d", &u, &v);
      long long sum0 = getsum(fa[u]), sum1 = getsum(u), sum2, Sum, sum3;
      int fa11, fa33, u1 = fa[u];
      fa11 = fa[fa[fa[u]]];
      fa33 = fa[fa[v]];
      flag[fa[u]] = flag[fa11] = flag[fa[fa[u]]] = 1,
      flag1[v] = flag1[fa[v]] = flag1[fa33] = 1;
      if (ss2[fa11].size() > 1) {
        mins = *ss2[fa11].begin();
        maxs = *(--ss2[fa11].end());
        Sum = getsum(fa11);
        mins += Sum, maxs += Sum;
        pos = ss1.find(mins);
        ss1.erase(pos);
        pos1 = ss1.find(maxs);
        ss1.erase(pos1);
      } else if (ss2[fa11].size()) {
        mins = *ss2[fa11].begin();
        Sum = getsum(fa11);
        mins += Sum;
        pos = ss1.find(mins);
        ss1.erase(pos);
      }
      if (!flag[fa33]) {
        if (ss2[fa33].size() > 1) {
          mins = *ss2[fa33].begin();
          maxs = *(--ss2[fa33].end());
          Sum = getsum(fa33);
          mins += Sum, maxs += Sum;
          pos = ss1.find(mins);
          ss1.erase(pos);
          pos1 = ss1.find(maxs);
          ss1.erase(pos1);
        } else if (ss2[fa33].size()) {
          mins = *ss2[fa33].begin();
          Sum = getsum(fa33);
          mins += Sum;
          pos = ss1.find(mins);
          ss1.erase(pos);
        }
      }
      Sum = getsum(fa11);
      pos = ss2[fa11].find(getsum1(fa[fa[u]]) - Sum);
      ss2[fa11].erase(pos);
      int fa1 = fa[fa[u]];
      if (ss2[fa1].size() > 1) {
        mins = *ss2[fa1].begin();
        maxs = *(--ss2[fa1].end());
        Sum = getsum(fa1);
        mins += Sum, maxs += Sum;
        pos = ss1.find(mins);
        ss1.erase(pos);
        pos1 = ss1.find(maxs);
        ss1.erase(pos1);
      } else if (ss2[fa1].size()) {
        mins = *ss2[fa1].begin();
        Sum = getsum(fa1);
        mins += Sum;
        pos = ss1.find(mins);
        ss1.erase(pos);
      }
      sum2 = getsum(fa1);
      sum3 = getsum(fa[u]);
      sum[fa1] -= sum3;
      pos = ss2[fa1].find(getsum1(fa[u]) - sum2);
      ss2[fa1].erase(pos);
      sum[fa[u]] -= sum1;
      du[fa[u]]--;
      sum3 = getsum(fa[u]);
      sum[fa1] += sum3;
      ss2[fa1].insert(getsum1(fa[u]) - sum2);
      ss2[fa11].insert(getsum1(fa1) - getsum(fa11));
      if (!flag1[fa1]) {
        if (ss2[fa1].size() > 1) {
          mins = *ss2[fa1].begin();
          maxs = *(--ss2[fa1].end());
          Sum = getsum(fa1);
          mins += Sum;
          maxs += Sum;
          ss1.insert(mins);
          ss1.insert(maxs);
        } else if (ss2[fa1].size()) {
          mins = *ss2[fa1].begin();
          Sum = getsum(fa1);
          mins += Sum;
          ss1.insert(mins);
        }
      }
      if (!flag1[fa11]) {
        if (ss2[fa11].size() > 1) {
          mins = *ss2[fa11].begin();
          maxs = *(--ss2[fa11].end());
          Sum = getsum(fa11);
          mins += Sum;
          maxs += Sum;
          ss1.insert(mins);
          ss1.insert(maxs);
        } else if (ss2[fa11].size()) {
          mins = *ss2[fa11].begin();
          Sum = getsum(fa11);
          mins += Sum;
          ss1.insert(mins);
        }
      }
      if (ss2[fa[u]].size() > 1) {
        mins = *ss2[fa[u]].begin();
        maxs = *(--ss2[fa[u]].end());
        du[fa[u]]++;
        Sum = getsum(fa[u]);
        du[fa[u]]--;
        mins += Sum, maxs += Sum;
        pos = ss1.find(mins);
        ss1.erase(pos);
        pos1 = ss1.find(maxs);
        ss1.erase(pos1);
      } else if (ss2[fa[u]].size()) {
        mins = *ss2[fa[u]].begin();
        du[fa[u]]++;
        Sum = getsum(fa[u]);
        du[fa[u]]--;
        pos = ss1.find(mins + Sum);
        ss1.erase(pos);
      }
      du[fa[u]]++;
      pos = ss2[fa[u]].find(getsum1(u) - sum0);
      du[fa[u]]--;
      ss2[fa[u]].erase(pos);
      if (!flag1[fa[u]]) {
        if (ss2[fa[u]].size() > 1) {
          mins = *ss2[fa[u]].begin();
          maxs = *(--ss2[fa[u]].end());
          Sum = getsum(fa[u]);
          mins += Sum;
          maxs += Sum;
          ss1.insert(mins);
          ss1.insert(maxs);
        } else if (ss2[fa[u]].size()) {
          mins = *ss2[fa[u]].begin();
          Sum = getsum(fa[u]);
          mins += Sum;
          ss1.insert(mins);
        }
      }
      Sum = getsum(fa33);
      pos = ss2[fa33].find(getsum1(fa[v]) - Sum);
      ss2[fa33].erase(pos);
      fa[u] = v;
      fa1 = fa[fa[u]];
      if (!flag[fa1]) {
        if (ss2[fa1].size() > 1) {
          mins = *ss2[fa1].begin();
          maxs = *(--ss2[fa1].end());
          Sum = getsum(fa1);
          mins += Sum, maxs += Sum;
          pos = ss1.find(mins);
          ss1.erase(pos);
          pos1 = ss1.find(maxs);
          ss1.erase(pos1);
        } else if (ss2[fa1].size()) {
          mins = *ss2[fa1].begin();
          Sum = getsum(fa1);
          mins += Sum;
          pos = ss1.find(mins);
          ss1.erase(pos);
        }
      }
      sum2 = getsum(fa1);
      sum3 = getsum(fa[u]);
      sum[fa1] -= sum3;
      pos = ss2[fa1].find(getsum1(fa[u]) - sum2);
      ss2[fa1].erase(pos);
      sum[fa[u]] += sum1;
      du[v]++;
      sum3 = getsum(fa[u]);
      sum[fa1] += sum3;
      ss2[fa1].insert(getsum1(fa[u]) - sum2);
      ss2[fa33].insert(getsum1(fa1) - getsum(fa33));
      if (ss2[fa1].size() > 1) {
        mins = *ss2[fa1].begin();
        maxs = *(--ss2[fa1].end());
        Sum = getsum(fa1);
        mins += Sum, maxs += Sum;
        ss1.insert(mins);
        ss1.insert(maxs);
      } else if (ss2[fa1].size()) {
        mins = *ss2[fa1].begin();
        Sum = getsum(fa1);
        mins += Sum;
        ss1.insert(mins);
      }
      if (ss2[fa33].size() > 1) {
        mins = *ss2[fa33].begin();
        maxs = *(--ss2[fa33].end());
        Sum = getsum(fa33);
        mins += Sum, maxs += Sum;
        ss1.insert(mins);
        ss1.insert(maxs);
      } else if (ss2[fa33].size()) {
        mins = *ss2[fa33].begin();
        Sum = getsum(fa33);
        mins += Sum;
        ss1.insert(mins);
      }
      if (!flag[fa[u]]) {
        if (ss2[fa[u]].size() > 1) {
          mins = *ss2[fa[u]].begin();
          maxs = *(--ss2[fa[u]].end());
          du[v]--;
          Sum = getsum(fa[u]);
          du[v]++;
          mins += Sum, maxs += Sum;
          pos = ss1.find(mins);
          ss1.erase(pos);
          pos1 = ss1.find(maxs);
          ss1.erase(pos1);
        } else if (ss2[fa[u]].size()) {
          mins = *ss2[fa[u]].begin();
          du[v]--;
          Sum = getsum(fa[u]);
          du[v]++;
          pos = ss1.find(mins + Sum);
          ss1.erase(pos);
        }
      }
      sum3 = getsum(fa[u]);
      ss2[fa[u]].insert(getsum1(u) - sum3);
      if (ss2[fa[u]].size() > 1) {
        mins = *ss2[fa[u]].begin();
        maxs = *(--ss2[fa[u]].end());
        Sum = getsum(fa[u]);
        mins += Sum;
        maxs += Sum;
        ss1.insert(mins);
        ss1.insert(maxs);
      } else if (ss2[fa[u]].size()) {
        mins = *ss2[fa[u]].begin();
        Sum = getsum(fa[u]);
        mins += Sum;
        ss1.insert(mins);
      }
      flag[u1] = flag[fa11] = flag[fa[u1]] = 0,
      flag1[v] = flag1[fa[v]] = flag1[fa33] = 0;
    }
    if (s == 2) {
      scanf("%d", &u);
      printf("%lld\n", getsum1(u));
    }
    if (s == 3) {
      mins = *ss1.begin();
      maxs = *(--ss1.end());
      printf("%lld %lld\n", mins, maxs);
    }
  }
  return 0;
}
