#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x(0), f(1);
  register char c(getchar());
  while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return f * x;
}
const int N = 8e5 + 10;
int n, a[N], D[N], ans;
vector<int> G[N];
namespace tree {
int dfn[N], tot, t[21][N << 1], dep[N], lg[N];
void dfs(int u) {
  dfn[u] = ++tot;
  t[0][tot] = dep[u];
  for (int v : G[u]) dep[v] = dep[u] + 1, dfs(v), t[0][++tot] = dep[u];
}
int lca(int x, int y) {
  x = dfn[x], y = dfn[y];
  if (x > y) swap(x, y);
  int l = lg[y - x + 1];
  return min(t[l][x], t[l][(y - (1 << l)) + 1]);
}
int dis(int x, int y) { return dep[x] + dep[y] - lca(x, y) * 2; }
void init() {
  lg[1] = 0;
  for (int i = 2; i <= N - 10; ++i) lg[i] = lg[i >> 1] + 1;
  dfs(dep[1] = 1);
  for (int i = 1; i < 20; ++i)
    for (int j = 1; j <= tot; ++j)
      if ((j + (1 << (i - 1))) <= tot)
        t[i][j] = min(t[i - 1][j], t[i - 1][j + (1 << (i - 1))]);
}
}  // namespace tree
struct node {
  int a, u, v;
} t[N], C, d;
node operator+(node x, node y) {
  if (!x.a || !y.a) {
    C.a = 0;
    return C;
  }
  int a = tree::dis(x.u, y.u);
  int b = tree::dis(x.u, y.v);
  int c = tree::dis(x.v, y.u);
  int d = tree::dis(x.v, y.v);
  int e = tree::dis(x.u, x.v);
  int f = tree::dis(y.u, y.v);
  if (a == b + f && a == e + c) return (node){1, x.u, y.u};
  if (b == e + d && b == a + f) return (node){1, x.u, y.v};
  if (c == e + a && c == f + d) return (node){1, x.v, y.u};
  if (d == b + e && d == f + c) return (node){1, x.v, y.v};
  if (e == a + c && e == b + d) return (node){1, x.u, x.v};
  if (f == a + b && f == c + d) return (node){1, y.u, y.v};
  C.a = 0;
  return C;
}
void built(int id, int l, int r) {
  if (l == r) {
    if (l != n) t[id] = (node){1, D[l], D[l]};
    return;
  }
  built(id << 1, l, ((l + r) >> 1)), built(id << 1 | 1, ((l + r) >> 1) + 1, r);
  t[id] = t[id << 1] + t[id << 1 | 1];
}
void change(int id, int l, int r, int k, int x) {
  if (l == r) {
    t[id].u = t[id].v = x;
    return;
  }
  if (((l + r) >> 1) >= k)
    change(id << 1, l, ((l + r) >> 1), k, x);
  else
    change(id << 1 | 1, ((l + r) >> 1) + 1, r, k, x);
  t[id] = t[id << 1] + t[id << 1 | 1];
}
void query(int id, int l, int r) {
  if (l == r) return;
  node tmp = d.a ? d + t[id << 1] : t[id << 1];
  if (tmp.a)
    d = tmp, ans = ((l + r) >> 1), query(id << 1 | 1, ((l + r) >> 1) + 1, r);
  else
    query(id << 1, l, ((l + r) >> 1));
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) D[a[i] = read()] = i;
  for (int i = 2; i <= n; ++i) G[read()].push_back(i);
  tree::init();
  built(1, 0, n);
  int Q = read();
  while (Q--) {
    int op = read();
    if (op == 1) {
      int x = read(), y = read();
      swap(a[x], a[y]);
      change(1, 0, n, a[x], x);
      change(1, 0, n, a[y], y);
    } else {
      d.a = 0;
      query(1, 0, n);
      cout << ans + 1 << '\n';
    }
  }
  return 0;
}
