#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
int ny;
inline char gc() {
  return pp1 == pp2 &&
                 (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)
             ? EOF
             : *pp1++;
}
inline int read() {
  int x = 0;
  for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)
    if (nc == 45) ny = -1;
  if (nc < 0) return nc;
  for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;
       x = (x << 3) + (x << 1) + (nc ^ 48))
    ;
  return x * ny;
}
int n, a[MAXN], pos[MAXN], fa[MAXN], d[MAXN], st[20][MAXN], tim, dfn[MAXN],
    tr[MAXN], Lg[MAXN];
vector<int> G[MAXN];
inline int cp(int x, int y) { return d[x] < d[y] ? x : y; }
inline int lca(int x, int y) {
  if (x == y) return x;
  x = dfn[x], y = dfn[y], (x > y ? swap(x, y), 0 : 0), y--;
  int k = Lg[y - x + 1];
  return cp(cp(st[k][x], st[k][y - (1 << k) + 1]), tr[y + 1]);
}
inline void dfs(int x) {
  d[x] = d[fa[x]] + 1, tr[dfn[x] = ++tim] = x, st[0][tim] = x;
  for (auto y : G[x])
    if (y != fa[x]) dfs(y), st[0][tim] = cp(st[0][tim], x);
}
inline int dis(int x, int y) { return d[x] + d[y] - 2 * d[lca(x, y)]; }
inline bool check(int a, int x, int y) {
  return !a || dis(a, x) + dis(a, y) == dis(x, y);
}
pair<int, int> val[MAXN << 2];
inline pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  if (a.first == 0) return b;
  if ((~a.first) && (~b.first)) {
    static int p[4];
    p[0] = a.first, p[1] = a.second, p[2] = b.first, p[3] = b.second;
    int Dis = -1, x = 0, y = 0;
    for (int i = (0); i <= (3); i++)
      for (int j = (i + 1); j <= (3); j++)
        if (dis(p[i], p[j]) >= Dis) Dis = dis(p[i], p[j]), x = p[i], y = p[j];
    int a = 0, b = 0;
    for (int i = (0); i <= (3); i++)
      if (p[i] != x && p[i] != y) !a ? a = p[i] : b = p[i];
    return (check(a, x, y) && check(b, x, y) ? make_pair(x, y)
                                             : make_pair(-1, -1));
  } else
    return make_pair(-1, -1);
}
inline void pushup(int x) { val[x] = val[x << 1] + val[x << 1 | 1]; }
inline void build(int x, int l, int r) {
  if (l == r) {
    val[x] = make_pair(pos[l], pos[l]);
    return;
  }
  int mid = l + r >> 1;
  build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r), pushup(x);
}
inline void upd(int x, int l, int r, int p) {
  if (l == r) {
    val[x] = make_pair(pos[l], pos[l]);
    return;
  }
  int mid = l + r >> 1;
  p <= mid ? upd(x << 1, l, mid, p) : upd(x << 1 | 1, mid + 1, r, p);
  pushup(x);
}
pair<int, int> now;
int ans;
inline void ask(int x, int l, int r) {
  if (l == r) {
    ans = l;
    return;
  }
  int mid = l + r >> 1;
  pair<int, int> t = now + val[x << 1];
  if (~t.first)
    now = t, ask(x << 1 | 1, mid + 1, r);
  else
    ask(x << 1, l, mid);
}
int main() {
  n = read();
  for (int i = (1); i <= (n); i++) pos[a[i] = read()] = i;
  for (int i = (2); i <= (n); i++) G[fa[i] = read()].push_back(i);
  dfs(1);
  Lg[0] = -1;
  for (int i = (1); i <= (n); i++) Lg[i] = Lg[i >> 1] + 1;
  for (int i = (1); i <= (19); i++)
    for (int j = (1); j <= (n - (1 << i) + 1); j++)
      st[i][j] = cp(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
  build(1, 0, n - 1);
  for (int q = read(); q--;) {
    int opt = read();
    if (opt == 1) {
      int x = read(), y = read();
      swap(a[x], a[y]), swap(pos[a[x]], pos[a[y]]), upd(1, 0, n - 1, a[x]),
          upd(1, 0, n - 1, a[y]);
    } else {
      if (~val[1].first)
        cout << n << "\n";
      else
        ans = 0, now = make_pair(0, 0), ask(1, 0, n - 1), cout << ans << "\n";
    }
  }
  return 0;
}
