#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 18;
const int MAXQ = 1 << 21;
const int MAXS = 1 << 19;
const int INF = 1 << 30;
void print(vector<int> &v) {
  cout << "v = ";
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i] << " ";
  }
  cout << endl;
}
vector<int> G[MAXN];
int N, P[MAXN], V[MAXN], H[MAXN];
int E[MAXN], L[MAXN], Time;
int C, Pos[MAXN * 3];
pair<int, int> Q[MAXQ * 2];
void init() {
  for (int i = 0; i < MAXQ * 2; ++i) {
    Q[i] = make_pair(INF, -1);
  }
}
void set_min(int p, pair<int, int> val) {
  for (p += MAXQ; p; p >>= 1) {
    Q[p] = min(Q[p], val);
  }
}
pair<int, int> get_min(int lo, int hi) {
  if (lo > hi) swap(lo, hi);
  pair<int, int> res = make_pair(INF, -1);
  for (lo += MAXQ, hi += MAXQ; lo <= hi; ++lo >>= 1, --hi >>= 1) {
    if ((lo & 1) == 1) res = min(res, Q[lo]);
    if ((hi & 1) == 0) res = min(res, Q[hi]);
  }
  return res;
}
void add_vertex(int u, int h) {
  Pos[u] = ++C;
  set_min(C, make_pair(h, u));
}
int LCA(int u, int v) {
  int pu = Pos[u];
  int pv = Pos[v];
  pair<int, int> r = get_min(pu, pv);
  return r.second;
}
void DFS(int u, int prev, int h) {
  H[u] = h;
  E[u] = ++Time;
  add_vertex(u, h);
  for (auto v : G[u]) {
    if (v != prev) {
      DFS(v, u, h + 1);
      add_vertex(u, h);
    }
  }
  L[u] = ++Time;
}
void test() {
  int u = 4, v = 6;
  printf("u=%d v=%d l=%d\n", u, v, LCA(u, v));
}
void read() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &P[i]);
    V[P[i]] = i;
  }
  for (int i = 2; i <= N; ++i) {
    int j;
    scanf("%d", &j);
    G[i].push_back(j);
    G[j].push_back(i);
  }
}
struct Item {
  int u, v, l;
  Item(int u = 0, int v = 0, int l = 0) : u(u), v(v), l(l) {}
};
Item S[MAXS * 2];
int Lo[MAXS * 2], Hi[MAXS * 2];
bool check(int u, int v, int w) {
  if (H[w] < H[u]) return false;
  int t = LCA(v, w);
  return t == w || t == v;
}
inline bool is_parent(int p, int u) { return E[p] <= E[u] && L[u] <= L[p]; }
inline bool inside(int p, int v, int w) {
  return is_parent(p, w) && is_parent(w, v);
}
int a[20], na;
int s[4], ns;
void add(int x) {
  if (find(s, s + ns, x) == s + ns) {
    s[ns++] = x;
  }
}
inline Item calc_item(int u1, int v1, int l1, int u2, int v2, int l2) {
  int l = LCA(l1, l2);
  ns = 0;
  add(u1);
  add(u2);
  add(v1);
  add(v2);
  na = 0;
  for (int i = 0; i < ns; ++i) {
    int u = s[i];
    bool ok = true;
    for (int j = 0; j < ns; ++j) {
      int v = s[j];
      if (v != u && inside(l, v, u)) {
        ok = false;
        break;
      }
    }
    if (ok) {
      a[na++] = u;
    }
    if (na > 2) {
      return Item();
    }
  }
  if (na == 1) {
    return Item(a[0], l, l);
  }
  if (LCA(a[0], a[1]) != l) {
    return Item();
  }
  return Item(a[0], a[1], l);
}
inline Item calc_item(int left, int right) {
  int u1 = S[left].u;
  int v1 = S[left].v;
  int l1 = S[left].l;
  int u2 = S[right].u;
  int v2 = S[right].v;
  int l2 = S[right].l;
  return calc_item(u1, v1, l1, u2, v2, l2);
}
Item calc(int l, int r) {
  int l1 = S[l].l;
  int l2 = S[r].l;
  if (!l1 || !l2) {
    return Item();
  }
  return calc_item(l, r);
}
void set_s(int p, Item val) {
  p += MAXS - 1;
  S[p] = val;
  while (p > 0) {
    p = (p - 1) / 2;
    S[p] = calc(p * 2 + 1, p * 2 + 2);
  }
}
void build_tree(int p, int lo, int hi) {
  Lo[p] = lo;
  Hi[p] = hi;
  if (lo < hi) {
    int mid = (lo + hi) / 2;
    int l = p * 2 + 1;
    int r = p * 2 + 2;
    build_tree(l, lo, mid);
    build_tree(r, mid + 1, hi);
  }
}
void build() {
  build_tree(0, 0, MAXS - 1);
  for (int i = 0; i < N; ++i) {
    set_s(i, Item(V[i], V[i], V[i]));
  }
}
inline void make_swap(int u, int v) {
  int pu = P[u];
  int pv = P[v];
  Item x = S[MAXS - 1 + pu];
  Item y = S[MAXS - 1 + pv];
  swap(P[u], P[v]);
  set_s(pu, Item());
  set_s(pv, Item());
  set_s(pu, y);
  set_s(pv, x);
}
inline void right(int &p, int &lo, int &hi) {
  int len = hi - lo + 1;
  lo = hi + 1;
  hi = lo + len - 1;
  ++p;
}
inline void left_down(int &p, int &lo, int &hi) {
  int len = hi - lo + 1;
  len /= 2;
  hi = lo + len - 1;
  p = p * 2 + 1;
}
inline bool merge(int p, int &u, int &v, int &l) {
  if (u == -1) {
    u = S[p].u;
    v = S[p].v;
    l = S[p].l;
    return true;
  }
  Item r = calc_item(u, v, l, S[p].u, S[p].v, S[p].l);
  if (r.l) {
    u = r.u;
    v = r.v;
    l = r.l;
    return true;
  }
  return false;
}
inline int get_mex() {
  int p = 0, lo = 0, hi = MAXS - 1, u = -1, v = -1, l = -1;
  int ans = -1;
  while (1) {
    bool fnd = false;
    while (1) {
      if (S[p].l > 0 && merge(p, u, v, l)) {
        ans = hi;
        fnd = true;
        break;
      }
      if (lo == hi) {
        break;
      }
      left_down(p, lo, hi);
    }
    if (!fnd) {
      break;
    }
    if (lo == hi || hi == MAXS - 1) {
      break;
    }
    right(p, lo, hi);
    left_down(p, lo, hi);
  }
  return ans + 1;
}
void print(Item &item) { printf("u=%d v=%d l=%d\n", item.u, item.v, item.l); }
int main() {
  init();
  read();
  DFS(1, 0, 1);
  int q;
  scanf("%d", &q);
  build();
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int u, v;
      scanf("%d %d", &u, &v);
      make_swap(u, v);
    } else {
      int r = get_mex();
      printf("%d\n", r);
    }
  }
  return 0;
}
