#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline void Max(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void Min(T &a, T b) {
  if (a > b) a = b;
}
const int N = 2e5 + 7;
int n, edc, tim, low;
int head[N], in[N], mi[N << 1][20], Log[N << 1], pos[N], rev[N], p[N];
struct edge {
  int lst, to;
  edge() {}
  edge(int lst, int to) : lst(lst), to(to) {}
} e[N * 2];
void Add(int a, int b) {
  e[++edc] = edge(head[a], b), head[a] = edc;
  e[++edc] = edge(head[b], a), head[b] = edc;
}
void dfs(int u, int fa) {
  in[u] = ++tim;
  mi[pos[u] = ++low][0] = u;
  for (int i = head[u], v = e[i].to; i; i = e[i].lst, v = e[i].to)
    if (v ^ fa) {
      dfs(v, u);
      mi[++low][0] = u;
    }
}
int Lca(int l, int r) {
  l = pos[l], r = pos[r];
  if (l > r) swap(l, r);
  int k = Log[r - l + 1];
  return in[mi[l][k]] < in[mi[r - (1 << k) + 1][k]] ? mi[l][k]
                                                    : mi[r - (1 << k) + 1][k];
}
struct data {
  int a, b, opt;
} t[N << 2];
void print(data a) { printf("%d %d %d\n", a.a, a.b, a.opt); }
bool inc(data x, data y) {
  int lca = Lca(x.a, x.b);
  return (Lca(lca, y.a) == lca &&
          (Lca(x.a, y.a) == y.a || Lca(x.b, y.a) == y.a)) &&
         (Lca(lca, y.b) == lca &&
          (Lca(x.a, y.b) == y.b || Lca(x.b, y.b) == y.b));
}
data operator+(data x, data y) {
  data res;
  if (x.opt == 1 || y.opt == 1) return res.opt = 1, res;
  if (x.opt == 2) return y;
  if (y.opt == 2) return x;
  res = (data){x.a, y.a, 0};
  if (inc(res, x) && inc(res, y)) goto A;
  res = (data){x.b, y.a, 0};
  if (inc(res, x) && inc(res, y)) goto A;
  res = (data){x.a, y.b, 0};
  if (inc(res, x) && inc(res, y)) goto A;
  res = (data){x.b, y.b, 0};
  if (inc(res, x) && inc(res, y)) goto A;
  res = (data){x.a, x.b, 0};
  if (inc(res, x) && inc(res, y)) goto A;
  res = (data){y.a, y.b, 0};
  if (inc(res, x) && inc(res, y)) goto A;
  res.opt = 1;
A:;
  return res;
}
void build(int l, int r, int o) {
  if (l == r) {
    t[o].a = t[o].b = rev[l], t[o].opt = 0;
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, o << 1);
  build(mid + 1, r, (o << 1 | 1));
  t[o] = t[o << 1] + t[(o << 1 | 1)];
}
void modify(int p, int l, int r, int o, int v) {
  if (l == r) {
    t[o].a = t[o].b = v, t[o].opt = 0;
    return;
  }
  int mid = l + r >> 1;
  if (p <= mid)
    modify(p, l, mid, o << 1, v);
  else
    modify(p, mid + 1, r, (o << 1 | 1), v);
  t[o] = t[o << 1] + t[(o << 1 | 1)];
}
int query(int l, int r, int o, data tmp) {
  if (!(tmp + t[o]).opt) return r;
  if (l == r) return -1;
  int mid = l + r >> 1, res;
  res = query(l, mid, o << 1, tmp);
  if (res < mid) return res;
  return max(res, query(mid + 1, r, (o << 1 | 1), tmp + t[o << 1]));
}
void gg(int l, int r, int o) {
  if (l == r) {
    printf("%d ", t[o].a);
    return;
  }
  int mid = l + r >> 1;
  gg(l, mid, o << 1);
  gg(mid + 1, r, (o << 1 | 1));
}
int main() {
  n = gi();
  for (int i = 1; i <= n; ++i) p[i] = gi(), rev[p[i]] = i;
  for (int i = 2; i <= n; ++i) Add(gi(), i);
  dfs(1, 0);
  Log[1] = 0;
  for (int i = 2; i <= low; ++i) Log[i] = Log[i >> 1] + 1;
  for (int k = 1; 1 << k <= low; ++k)
    for (int i = 1; i + (1 << k) - 1 <= low; ++i)
      mi[i][k] = in[mi[i][k - 1]] < in[mi[i + (1 << k - 1)][k - 1]]
                     ? mi[i][k - 1]
                     : mi[i + (1 << k - 1)][k - 1];
  build(0, n - 1, 1);
  int Q = gi();
  int opt, a, b;
  while (Q--) {
    opt = gi();
    if (opt == 1) {
      a = gi(), b = gi();
      modify(p[b], 0, n - 1, 1, a);
      modify(p[a], 0, n - 1, 1, b);
      swap(p[a], p[b]);
    } else {
      printf("%d\n", query(0, n - 1, 1, (data){0, 0, 2}) + 1);
    }
  }
  return 0;
}
