#include <bits/stdc++.h>
using namespace std;
int dfn[200010], p[400010], tim;
int g[400010][21];
int dep[200010], w[400010];
pair<int, int> tree[800010];
int a[200010], d[200010];
int n, m;
int addnum, vel[400010], ne[400010], head[200010];
void add(int u, int v) {
  addnum++, vel[addnum] = v, ne[addnum] = head[u], head[u] = addnum;
}
int read() {
  int ans = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  return ans;
}
void dfs(int u, int fa) {
  dfn[u] = ++tim;
  p[tim] = u;
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa) continue;
    dep[v] = dep[u] + 1;
    dfs(v, u);
    p[++tim] = u;
  }
}
int calc(int x, int y) {
  if (dep[x] < dep[y]) return x;
  return y;
}
void init() {
  w[0] = -1;
  for (int i = 1; i <= tim; i++) w[i] = w[i >> 1] + 1;
  for (int i = 1; i <= tim; i++) g[i][0] = p[i];
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= tim - (1 << i) + 1; j++)
      g[j][i] = calc(g[j][i - 1], g[j + (1 << (i - 1))][i - 1]);
}
int dis(int x, int y) {
  if (dfn[x] > dfn[y]) swap(x, y);
  int dt = w[dfn[y] - dfn[x] + 1];
  int lca = calc(g[dfn[x]][dt], g[dfn[y] - (1 << dt) + 1][dt]);
  return dep[x] + dep[y] - dep[lca] * 2;
}
pair<int, int> merge(int x, int y, int z) {
  int da = dis(x, y), db = dis(y, z), dc = dis(x, z);
  if (da + db == dc) return make_pair(x, z);
  if (da + dc == db) return make_pair(y, z);
  if (db + dc == da) return make_pair(x, y);
  return make_pair(-1, -1);
}
pair<int, int> merge(pair<int, int> x, pair<int, int> y) {
  if (x.first == -1) return x;
  if (y.first == -1) return y;
  if (!x.first) return y;
  if (!y.first) return x;
  pair<int, int> num = merge(x.first, x.second, y.first);
  if (num.first == -1) return num;
  num = merge(num.first, num.second, y.second);
  return num;
}
void build(int rex, int l, int r) {
  if (l == r) {
    tree[rex] = make_pair(d[l], d[l]);
    return;
  }
  int mid = (l + r) >> 1;
  build(rex + rex, l, mid);
  build(rex + rex + 1, mid + 1, r);
  tree[rex] = merge(tree[rex + rex], tree[rex + rex + 1]);
}
void ins(int rex, int l, int r, int x) {
  if (l == r) {
    tree[rex] = make_pair(d[l], d[l]);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    ins(rex + rex, l, mid, x);
  else
    ins(rex + rex + 1, mid + 1, r, x);
  tree[rex] = merge(tree[rex + rex], tree[rex + rex + 1]);
}
int solve(int rex, int l, int r, pair<int, int> pre) {
  if (l == r) {
    pair<int, int> dt = merge(pre, tree[rex]);
    if (dt.first == -1) return l;
    return l + 1;
  }
  int mid = (l + r) >> 1;
  pair<int, int> dt = merge(pre, tree[rex + rex]);
  if (dt.first == -1)
    return solve(rex + rex, l, mid, pre);
  else
    return solve(rex + rex + 1, mid + 1, r, dt);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read() + 1, d[a[i]] = i;
  for (int i = 2; i <= n; i++) {
    int x = read();
    add(x, i);
  }
  dfs(1, -1);
  init();
  build(1, 1, n);
  m = read();
  while (m--) {
    int cas = read();
    if (cas == 1) {
      int x = read(), y = read();
      swap(a[x], a[y]);
      d[a[x]] = x;
      d[a[y]] = y;
      ins(1, 1, n, a[x]), ins(1, 1, n, a[y]);
    } else
      printf("%d\n", solve(1, 1, n, make_pair(0, 0)) - 1);
  }
}
