#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
const long long INF = 1e15;
template <class o>
void qr(o &x) {
  char c = getchar();
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o>
void pr1(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar('\n');
}
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long power(long long a, long long b = mod - 2, long long p = mod) {
  long long c = 1;
  while (b) {
    if (b & 1) c = c * a % p;
    b /= 2;
    a = a * a % p;
  }
  return c;
}
template <class o>
void cmax(o &x, o y) {
  if (x < y) x = y;
}
void cmax(int &x, int y) {
  x = x - y >> 31 ? y : x;
  ;
}
template <class o>
void cmin(o &x, o y) {
  if (x > y) x = y;
}
void cmin(int &x, int y) { x = x - y >> 31 ? x : y; }
template <class o>
void ad(o &x, o y) {
  x += y;
  if (x >= mod) x -= mod;
}
template <class o>
void dl(o &x, o y) {
  x -= y;
  if (x < 0) x += mod;
}
long long jc[N], inv[N];
void jc_init(int n) {
  jc[0] = 1;
  for (int i = 1; i <= n; i++) jc[i] = jc[i - 1] * i % mod;
  inv[n] = power(jc[n]);
  for (int i = n; i; i--) inv[i - 1] = inv[i] * i % mod;
}
long long C(int x, int y) {
  if (x < y || y < 0) return 0;
  return jc[x] * inv[y] % mod * inv[x - y] % mod;
}
int n, m, p[N], dep[N], f[N][20], lg[N], b[N], id[N], tot;
vector<int> e[N];
void add(int x, int y) { e[x].push_back(y); }
void dfs(int x) {
  id[x] = ++tot;
  b[tot] = x;
  for (int y : e[x]) dep[y] = dep[x] + 1, dfs(y), b[++tot] = x;
}
int Min(int x, int y) { return dep[x] - dep[y] >> 31 ? x : y; }
void init() {
  lg[0] = -1;
  for (int i = 1; i <= tot; i++) lg[i] = lg[i >> 1] + 1, f[i][0] = b[i];
  for (int j = 1; j <= lg[tot]; j++)
    for (int i = tot - (1 << j) + 1; i > 0; i--)
      f[i][j] = Min(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
}
int lca(int x, int y) {
  if ((x = id[x]) > (y = id[y])) swap(x, y);
  int k = lg[y - x + 1];
  return Min(f[x][k], f[y - (1 << k) + 1][k]);
}
bool in(int x, int y, int z) {
  int tp = lca(x, z);
  return (lca(x, y) == y || lca(y, z) == y) && lca(tp, y) == tp;
}
struct L {
  int x, y;
  L(int a = 0, int b = 0) {
    x = a;
    y = b;
  }
  L operator+(int z) {
    if (!x || !z) return L();
    if (in(x, z, y))
      return *this;
    else if (in(z, x, y))
      return L(z, y);
    else if (in(x, y, z))
      return L(x, z);
    return L();
  }
  L operator+(L b) const {
    L c = *this;
    c = c + b.x + b.y;
    return c;
  }
} tr[N * 4];
int pos[N];
void bt(int x, int l, int r) {
  if (l == r) {
    tr[x] = L(pos[l], pos[l]);
    return;
  }
  int mid = (l + r) / 2;
  bt((x << 1), l, mid);
  bt((x << 1 | 1), mid + 1, r);
  tr[x] = tr[(x << 1)] + tr[(x << 1 | 1)];
}
void change(int x, int l, int r, int p) {
  if (l == r) {
    tr[x] = L(pos[l], pos[l]);
    return;
  }
  int mid = (l + r) / 2;
  if (p <= mid)
    change((x << 1), l, mid, p);
  else
    change((x << 1 | 1), mid + 1, r, p);
  tr[x] = tr[(x << 1)] + tr[(x << 1 | 1)];
}
void ask() {
  int x = 1, l = 1, r = n;
  L now = L(), t;
  while (l < r) {
    int mid = (l + r) / 2;
    if (!now.x)
      t = tr[(x << 1)];
    else
      t = now + tr[(x << 1)];
    if (!t.x)
      x = (x << 1), r = mid;
    else
      now = t, x = (x << 1 | 1), l = mid + 1;
  }
  if ((now + tr[x]).x) l++;
  pr2(l - 1);
}
void solve() {
  qr(n);
  for (int i = 1; i <= n; i++) qr(p[i]), pos[++p[i]] = i;
  for (int i = 2, fa; i <= n; i++) qr(fa), add(fa, i);
  dfs(1);
  init();
  bt(1, 1, n);
  qr(m);
  while (m--) {
    int op, l, r;
    qr(op);
    if (op == 1) {
      qr(l);
      qr(r);
      if (l ^ r) {
        swap(p[l], p[r]);
        swap(pos[p[l]], pos[p[r]]);
        change(1, 1, n, p[l]);
        change(1, 1, n, p[r]);
      }
    } else
      ask();
  }
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
