#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long first) {
  return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;
}
inline int rd() {
  int first = 0;
  char p = getchar();
  while (p < '0' || p > '9') p = getchar();
  while (p >= '0' && p <= '9') first = first * 10 + p - '0', p = getchar();
  return first;
}
const int N = 1e6 + 50;
int n, a[N], pos[N], L[N], R[N];
vector<int> g[N];
int fa[N], dep[N], sz[N], top[N], son[N];
void dfs(int first, int f, int d) {
  L[first] = ++*L;
  sz[first] = 1, dep[first] = d, fa[first] = f;
  for (int second : g[first])
    if (second != f) {
      dfs(second, first, d + 1), sz[first] += sz[second];
      if (sz[second] > sz[son[first]]) son[first] = second;
    }
  R[first] = *L;
}
void dfs(int first, int tf) {
  top[first] = tf;
  if (son[first]) dfs(son[first], tf);
  for (int second : g[first])
    if (!top[second]) dfs(second, second);
}
int lca(int first, int second) {
  while (top[first] != top[second]) {
    if (dep[top[first]] < dep[top[second]]) swap(first, second);
    first = fa[top[first]];
  }
  return dep[first] < dep[second] ? first : second;
}
int chk(int s, int t, int first) {
  if (first == s || first == t) return 1;
  int l = lca(s, t);
  if (lca(first, l) == l)
    return lca(s, first) == first || lca(t, first) == first;
  return 0;
}
struct _ {
  int s, t;
  _ operator+(const _ &rhs) const {
    _ ret;
    if (s == 0) return rhs;
    if (rhs.s == 0) return *this;
    if (s == -1 || rhs.s == -1) return {-1, -1};
    int a[] = {s, t, rhs.s, rhs.t};
    for (int i = 0; i <= 3; ++i)
      for (int j = i + 1; j <= 3; ++j) {
        int ok = 1;
        for (int k = 0; k <= 3; ++k)
          if (!chk(a[i], a[j], a[k])) {
            ok = 0;
            break;
          }
        if (ok) return {a[i], a[j]};
      }
    return {-1, -1};
  }
} tr[N << 2];
void build(int o, int l, int r) {
  if (l == r)
    tr[o].s = tr[o].t = pos[l];
  else
    build((o << 1), l, ((l + r) >> 1)),
        build(((o << 1) | 1), ((l + r) >> 1) + 1, r),
        tr[o] = tr[(o << 1)] + tr[((o << 1) | 1)];
}
void upd(int o, int l, int r, int first) {
  if (l == r)
    tr[o].s = tr[o].t = pos[l];
  else {
    ((l + r) >> 1) >= first ? upd((o << 1), l, ((l + r) >> 1), first)
                            : upd(((o << 1) | 1), ((l + r) >> 1) + 1, r, first);
    tr[o] = tr[(o << 1)] + tr[((o << 1) | 1)];
  }
}
int query(int o, int l, int r, _ p) {
  if (l == r) return (p + tr[o]).s > 0;
  _ t = (p + tr[(o << 1)]);
  if (t.s < 0) return query((o << 1), l, ((l + r) >> 1), p);
  return ((l + r) >> 1) - l + 1 +
         query(((o << 1) | 1), ((l + r) >> 1) + 1, r, t);
}
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 f;
    scanf("%d", &f);
    g[f].push_back(i);
  }
  dfs(1, 0, 0), dfs(1, 1);
  build(1, 1, n);
  int q;
  scanf("%d", &q);
  while (q--) {
    int op, first, second;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &first, &second);
      swap(a[first], a[second]);
      swap(pos[a[first]], pos[a[second]]);
      upd(1, 1, n, a[first]);
      upd(1, 1, n, a[second]);
    } else
      printf("%d\n", query(1, 1, n, {0, 0}));
  }
}
