#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 2e5 + 10;
int n, q, typ, x, y, cnt, ans;
int a[maxn], in[maxn], out[maxn];
int dep[maxn], fc[21], fa[21][maxn];
vector<int> G[maxn];
pair<int, int> res;
inline void dfs(int u) {
  in[u] = ++cnt;
  for (int i = 1; fc[i] <= dep[u]; ++i) fa[i][u] = fa[i - 1][fa[i - 1][u]];
  for (int i = 0, len = G[u].size(); i < len; ++i) {
    dep[G[u][i]] = dep[u] + 1;
    fa[0][G[u][i]] = u;
    dfs(G[u][i]);
  }
  out[u] = ++cnt;
}
inline int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 0, t = dep[x] - dep[y]; t; ++i)
    if (t & fc[i]) x = fa[i][x], t ^= fc[i];
  for (int i = 20; ~i; --i)
    if (fa[i][x] ^ fa[i][y]) x = fa[i][x], y = fa[i][y];
  return x == y ? x : fa[0][x];
}
namespace Segment {
pair<int, int> T[maxn << 2];
bool anc(int x, int y) { return in[x] <= in[y] && out[x] >= out[y]; }
pair<int, int> check(pair<int, int> x, int y) {
  if (!x.first || !y) return make_pair(0, 0);
  if (anc(x.first, x.second)) swap(x.first, x.second);
  if (anc(x.second, x.first)) {
    if (anc(x.first, y)) return make_pair(y, x.second);
    if (anc(x.second, y)) {
      if (anc(y, x.first)) return x;
      if (LCA(x.first, y) == x.second) return make_pair(x.first, y);
      return make_pair(0, 0);
    }
    return make_pair(y, x.first);
  }
  if (anc(x.first, y)) return make_pair(y, x.second);
  if (anc(x.second, y)) return make_pair(x.first, y);
  if (!anc(LCA(x.first, x.second), y)) return make_pair(0, 0);
  if (!anc(y, x.first) && !anc(y, x.second)) return make_pair(0, 0);
  return x;
}
pair<int, int> merge(pair<int, int> x, pair<int, int> y) {
  if (x.first == -1) return y;
  x = check(x, y.first);
  x = check(x, y.second);
  return x;
}
void update(int rt, int l, int r, int pos, int x) {
  if (l == r) {
    T[rt] = make_pair(x, x);
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    update((rt << 1), l, mid, pos, x);
  else
    update((rt << 1 | 1), mid + 1, r, pos, x);
  T[rt] = merge(T[(rt << 1)], T[(rt << 1 | 1)]);
}
bool query(int rt, int l, int r) {
  pair<int, int> tmp = merge(res, T[rt]);
  if (tmp.first) {
    res = tmp;
    ans = r;
    return true;
  }
  if (l == r) return false;
  int mid = l + r >> 1;
  if (query((rt << 1), l, mid)) query((rt << 1 | 1), mid + 1, r);
  return false;
}
}  // namespace Segment
using namespace Segment;
int main() {
  n = read();
  fc[0] = 1;
  for (int i = 1; i <= n; ++i) a[i] = read() + 1;
  for (int i = 2; i <= n; ++i) G[read()].push_back(i);
  for (int i = 1; i <= 20; ++i) fc[i] = fc[i - 1] << 1;
  dfs(1);
  for (int i = 1; i <= n; ++i) update(1, 1, n, a[i], i);
  q = read();
  while (q--) {
    typ = read();
    if (typ == 1) {
      x = read();
      y = read();
      swap(a[x], a[y]);
      update(1, 1, n, a[x], x);
      update(1, 1, n, a[y], y);
    } else {
      res = make_pair(-1, 0);
      ans = 1;
      query(1, 1, n);
      printf("%d\n", ans);
    }
  }
  return 0;
}
