#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 2e5 + 10;
const int L = 18;
struct node {
  int u, v, f;
  node() {
    u = v = 0;
    f = 1;
  }
};
int p[N], pos[N], par[N][L], h[N], n;
node seg[4 * N], lst;
int getPar(int v, int k) {
  for (int i = 0; i < L; i++)
    if (k >> i & 1) v = par[v][i];
  return v;
}
int getLca(int u, int v) {
  if (h[v] < h[u]) swap(u, v);
  v = getPar(v, h[v] - h[u]);
  if (u == v) return v;
  for (int i = L - 1; i >= 0; i--)
    if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
  return par[u][0];
}
int dis(int u, int v) { return h[u] + h[v] - 2 * h[getLca(u, v)]; }
node merge(node a, node b) {
  if (!a.u) return b;
  if (!b.u) return a;
  node c;
  c.u = c.v = -1;
  c.f = 0;
  if (!a.f || !b.f) return c;
  int A[4] = {a.u, a.v, b.u, b.v}, B[4] = {0, 1, 2, 3}, d[4][4];
  for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 4; j++) d[i][j] = d[j][i] = dis(A[i], A[j]);
    d[i][i] = 0;
  }
  do {
    if (d[B[0]][B[1]] + d[B[1]][B[2]] + d[B[2]][B[3]] == d[B[0]][B[3]]) {
      c.u = A[B[0]];
      c.v = A[B[3]];
      c.f = 1;
      return c;
    }
  } while (next_permutation(B, B + 4));
  return c;
}
void build(int l = 0, int r = n, int id = 1) {
  if (r - l == 1) {
    seg[id].u = seg[id].v = pos[l];
    seg[id].f = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, (id << 1));
  build(mid, r, (id << 1 | 1));
  seg[id] = merge(seg[(id << 1)], seg[(id << 1 | 1)]);
}
void modify(int x, int l = 0, int r = n, int id = 1) {
  if (r - l == 1) {
    seg[id].u = seg[id].v = pos[l];
    seg[id].f = 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (x < mid)
    modify(x, l, mid, (id << 1));
  else
    modify(x, mid, r, (id << 1 | 1));
  seg[id] = merge(seg[(id << 1)], seg[(id << 1 | 1)]);
}
int get(int l = 0, int r = n, int id = 1) {
  if (r - l == 1) {
    lst = merge(lst, seg[id]);
    return l + lst.f;
  }
  int mid = (l + r) >> 1;
  node tmp = merge(lst, seg[(id << 1)]);
  if (tmp.f) {
    lst = merge(lst, seg[(id << 1)]);
    return get(mid, r, (id << 1 | 1));
  }
  return get(l, mid, (id << 1));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i], pos[p[i]] = i;
  for (int i = 2; i <= n; i++) cin >> par[i][0], h[i] = h[par[i][0]] + 1;
  for (int i = 2; i <= n; i++)
    for (int j = 1; j < L; j++) par[i][j] = par[par[i][j - 1]][j - 1];
  build();
  int q;
  cin >> q;
  while (q--) {
    int typ;
    cin >> typ;
    if (typ == 1) {
      int i, j;
      cin >> i >> j;
      swap(pos[p[i]], pos[p[j]]);
      swap(p[i], p[j]);
      modify(p[i]);
      modify(p[j]);
    } else {
      lst.u = lst.v = 0;
      lst.f = 1;
      cout << get() << '\n';
    }
  }
  return 0;
}
