#include <bits/stdc++.h>
using namespace std;
int n;
int p[200010];
int pos[200010];
const int M = 19;
int dep[200010];
int fa[200010][M];
int getlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int need = dep[u] - dep[v], now = 0;
  while (need) {
    if (need & 1) u = fa[u][now];
    need >>= 1;
    now++;
  }
  if (u == v) return u;
  for (int i = M - 1; i >= 0; i--)
    if (fa[u][i] != fa[v][i]) {
      u = fa[u][i];
      v = fa[v][i];
    }
  return fa[u][0];
}
int dist(int u, int v) {
  int lca = getlca(u, v);
  return dep[u] + dep[v] - 2 * dep[lca];
}
struct Path {
  int u, v;
  Path(int uu = 0, int vv = 0) {
    u = uu;
    v = vv;
  }
} T[800010];
Path merge(Path p, int x) {
  int u = p.u, v = p.v;
  if (u == -1 || x == -1) return Path(-1, -1);
  int dis1 = dist(u, v);
  int dis2 = dist(v, x);
  int dis3 = dist(u, x);
  if (dis1 + dis2 == dis3) return Path(u, x);
  if (dis1 + dis3 == dis2) return Path(v, x);
  if (dis2 + dis3 == dis1) return Path(u, v);
  return Path(-1, -1);
}
Path merge(Path x, Path y) {
  x = merge(x, y.u);
  x = merge(x, y.v);
  return x;
}
void update(int root) {
  T[root] = merge(T[root << 1], T[root << 1 | 1]);
  return;
}
void build(int root, int l, int r) {
  if (l == r) {
    T[root] = Path(pos[l], pos[l]);
    return;
  }
  int mid = (l + r) >> 1;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
  update(root);
  return;
}
void change(int root, int l, int r, int x) {
  if (l == r) {
    T[root] = Path(pos[l], pos[l]);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    change(root << 1, l, mid, x);
  else
    change(root << 1 | 1, mid + 1, r, x);
  update(root);
  return;
}
int query(int root, int l, int r, Path x) {
  if (l == r) {
    Path y = merge(x, pos[l]);
    if (y.u == -1) return l;
    return l + 1;
  }
  int mid = (l + r) >> 1;
  Path y = merge(x, T[root << 1]);
  if (y.u == -1) return query(root << 1, l, mid, x);
  return query(root << 1 | 1, mid + 1, r, y);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    pos[p[i]] = i;
  }
  for (int i = 2; i <= n; i++) {
    scanf("%d", &fa[i][0]);
    dep[i] = dep[fa[i][0]] + 1;
    for (int j = 1; j < M; j++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  }
  build(1, 0, n - 1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int u, v;
      scanf("%d %d", &u, &v);
      swap(p[u], p[v]);
      swap(pos[p[u]], pos[p[v]]);
      change(1, 0, n - 1, p[u]);
      change(1, 0, n - 1, p[v]);
    } else
      printf("%d\n", query(1, 0, n - 1, Path(pos[0], pos[0])));
  }
  return 0;
}
