#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
int n, m;
int a[1 << 18], pos[1 << 18];
vector<int> nei[1 << 18];
int bg[1 << 18], en[1 << 18];
vector<int> ord;
int N[20][1 << 19];
void inline dfs(int now) {
  bg[now] = ((int)(ord).size());
  ord.push_back(now);
  for (int i = 0; i < (((int)(nei[now]).size())); ++i) {
    int to = nei[now][i];
    dfs(to);
    ord.push_back(now);
  }
  en[now] = ((int)(ord).size());
}
int inline lca(int u, int v) {
  if (bg[u] > bg[v]) swap(u, v);
  int dis = 31 - __builtin_clz(bg[v] - bg[u]);
  return min(N[dis][bg[u]], N[dis][bg[v] - (1 << dis) + 1]);
}
bool inline On(int u, int v, int x) {
  int w = lca(u, v);
  return bg[x] >= bg[w] && en[x] <= en[w] &&
         ((bg[u] >= bg[x] && en[u] <= en[x]) ||
          (bg[v] >= bg[x] && en[v] <= en[x]));
}
pair<int, int> dt[1 << 20];
bool inline can(int u, int v, int a, int b) {
  return On(u, v, a) && On(u, v, b);
}
pair<int, int> inline merge(pair<int, int> a, pair<int, int> b) {
  if (!~a.first || !~b.first) return make_pair(-1, -1);
  if (!a.first) return b;
  int c = a.first, d = a.second, e = b.first, f = b.second;
  if (can(c, d, e, f)) return make_pair(c, d);
  if (can(c, e, d, f)) return make_pair(c, e);
  if (can(c, f, d, e)) return make_pair(c, f);
  if (can(d, e, c, f)) return make_pair(d, e);
  if (can(d, f, c, e)) return make_pair(d, f);
  if (can(e, f, c, d)) return make_pair(e, f);
  return make_pair(-1, -1);
}
void inline pu(int now) { dt[now] = merge(dt[now << 1], dt[now << 1 | 1]); }
void inline init(int now = 1, int nl = 1, int nr = n) {
  if (nl == nr) return void(dt[now] = make_pair(pos[nl], pos[nl]));
  int m = (nl + nr) >> 1;
  init(now << 1, nl, m);
  init(now << 1 | 1, m + 1, nr);
  pu(now);
}
void inline change(int to, int x, int now = 1, int nl = 1, int nr = n) {
  if (nl == nr) return void(dt[now] = make_pair(x, x));
  int m = (nl + nr) >> 1;
  m >= to ? change(to, x, now << 1, nl, m)
          : change(to, x, now << 1 | 1, m + 1, nr);
  pu(now);
}
int inline find(pair<int, int> cur = make_pair(0, 0), int now = 1, int nl = 1,
                int nr = n) {
  if (nl == 1 && ~dt[now].first) return nr;
  if (nl == nr) return nl - 1;
  int m = (nl + nr) >> 1;
  pair<int, int> ml = merge(cur, dt[now << 1]);
  if (!~ml.first)
    return find(cur, now << 1, nl, m);
  else
    return find(ml, now << 1 | 1, m + 1, nr);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= (n); ++i) scanf("%d", a + i), ++a[i], pos[a[i]] = i;
  for (int i = (2); i <= (n); ++i) {
    int fa;
    scanf("%d", &fa);
    nei[fa].push_back(i);
  }
  dfs(1);
  m = ((int)(ord).size());
  for (int i = 0; i < (m); ++i) N[0][i] = ord[i];
  for (int i = 0; i < (19); ++i)
    for (int j = 0; j < (m); ++j) {
      if (j + (1 << i) < m)
        N[i + 1][j] = min(N[i][j], N[i][j + (1 << i)]);
      else
        N[i + 1][j] = N[i][j];
    }
  init();
  int q;
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 2) {
      printf("%d\n", find());
    } else {
      int u, v;
      scanf("%d%d", &u, &v);
      int au = a[u], av = a[v];
      change(au, v);
      change(av, u);
      swap(a[u], a[v]);
      swap(pos[au], pos[av]);
    }
  }
  return 0;
}
