#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
template <class T>
void rd(T &x) {
  x = 0;
  int f = 0;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
}
struct qwe {
  int a, b, lc, ff;
} shu[200005 << 2], PP, rc;
int cnt, al[200005 << 1], cl[200005 << 1], kk[200005];
int Q, P, ans, ss[200005], sn[200005], ii[200005];
int df, epf[200005 << 1], fa[200005 << 1][20], dfn[200005], se[200005];
int Mn(int x, int y) { return se[x] < se[y] ? x : y; }
int lca(int x, int y) {
  if (x == y) return x;
  if (dfn[x] > dfn[y]) swap(x, y);
  int l = epf[dfn[y] - dfn[x] + 1];
  return Mn(fa[dfn[y]][l], fa[dfn[x] + (1 << l) - 1][l]);
}
qwe pushup(qwe &l, qwe &r) {
  if (l.ff == -1 || r.ff == -1) return (qwe){0, 0, 0, -1};
  int uup[4][4], tf[4], f = 0, fg;
  tf[0] = l.a, tf[1] = l.b, tf[2] = r.a, tf[3] = r.b;
  uup[0][1] = uup[1][0] = l.lc;
  uup[2][3] = uup[3][2] = r.lc;
  for (int i = 0; i < 4; ++i)
    for (int j = i + 1; j < 4; ++j)
      if (i + j != 1 && i + j != 5) {
        uup[i][j] = uup[j][i] = lca(tf[i], tf[j]);
      }
  for (int i = 0; i < 4; ++i)
    for (int j = i + 1; j < 4; ++j) {
      fg = 1;
      for (int k = 0; k < 4; ++k)
        if (k != i && k != j &&
            (!((uup[k][i] == tf[k] || uup[k][j] == tf[k]) &&
               lca(tf[k], uup[i][j]) == uup[i][j])))
          fg = 0;
      if (fg) return (qwe){tf[i], tf[j], uup[i][j], 1};
    }
  return (qwe){0, 0, 0, -1};
}
void init(int l, int r, int bao) {
  if (l == r) {
    shu[bao] = (qwe){sn[l], sn[l], sn[l], 1};
    return;
  }
  int mid = l + r >> 1;
  init(l, mid, bao << 1);
  init(mid + 1, r, bao << 1 | 1);
  shu[bao] = pushup(shu[bao << 1], shu[bao << 1 | 1]);
}
void cg(int l, int r, int bao) {
  if (l == r && (l == Q || l == P)) {
    shu[bao] = (qwe){sn[l], sn[l], sn[l], 1};
    return;
  }
  int mid = l + r >> 1;
  if ((Q <= mid && Q >= l) || (P <= mid && P >= l)) cg(l, mid, bao << 1);
  if ((Q > mid && Q <= r) || (P > mid && P <= r)) cg(mid + 1, r, bao << 1 | 1);
  shu[bao] = pushup(shu[bao << 1], shu[bao << 1 | 1]);
}
void sol(int l, int r, int bao) {
  if (shu[bao].ff != -1) {
    if (PP.ff == 2) {
      PP = shu[bao];
      ans = r;
      return;
    } else {
      rc = pushup(PP, shu[bao]);
      if (rc.ff == 1) {
        PP = rc, ans = r;
        return;
      }
    }
  }
  if (l == r) return;
  int mid = l + r >> 1;
  sol(l, mid, bao << 1);
  if (ans == mid) sol(mid + 1, r, bao << 1 | 1);
}
void dfs(int x, int y) {
  se[x] = se[y] + 1;
  dfn[x] = ++df;
  fa[df][0] = x;
  for (int i = kk[x]; i; i = cl[i])
    if (al[i] != y) {
      dfs(al[i], x);
      fa[++df][0] = x;
    }
}
void rmq() {
  int l = 0;
  while ((1 << l + 1) <= df) {
    ++l;
    for (int i = 1 << l - 1; i < (1 << l); ++i) epf[i] = l - 1;
  }
  for (int i = 1 << l; i <= df; ++i) epf[i] = l;
  for (int i = 1; i <= l; ++i)
    for (int j = 1 << i; j <= df; ++j)
      fa[j][i] = Mn(fa[j][i - 1], fa[j - (1 << i - 1)][i - 1]);
}
void jia(int x, int y) {
  al[++cnt] = y;
  cl[cnt] = kk[x];
  kk[x] = cnt;
}
void print(int x) {
  if (x >= 10) print(x / 10);
  putchar('0' + x % 10);
}
int main() {
  int n, q, x, y;
  rd(n);
  for (int i = 1; i <= n; ++i) {
    rd(ss[i]);
    ++ss[i];
    sn[ss[i]] = i;
  }
  for (int i = 2; i <= n; ++i) {
    rd(x);
    jia(i, x);
    jia(x, i);
    ++ii[i];
    ++ii[x];
  }
  if (n != 2)
    for (int i = 1; i <= n; ++i)
      if (ii[i] != 1) {
        dfs(i, 0);
        rmq();
        break;
      }
  init(1, n, 1);
  rd(q);
  while (q--) {
    rd(x);
    if (x == 1) {
      rd(x);
      rd(y);
      swap(sn[ss[x]], sn[ss[y]]);
      swap(ss[x], ss[y]);
      Q = ss[x];
      P = ss[y];
      cg(1, n, 1);
    } else {
      ans = 0;
      if (n == 2) {
        puts("2");
        continue;
      }
      PP.ff = 2;
      sol(1, n, 1);
      print(ans);
      putchar('\n');
    }
  }
  return 0;
}
