#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int read() {
  int number = 0, c = getchar();
  for (; !(c > 47 && c < 58); c = getchar())
    ;
  for (; (c > 47 && c < 58); c = getchar())
    number = (number << 3) + (number << 1) + c - 48;
  return number;
}
int tourTime, Log2[N << 1];
int pos[N], level[N];
vector<int> G[N];
pair<int, int> tour[19][N << 1];
void dfs(int u) {
  pos[u] = ++tourTime;
  tour[0][tourTime] = make_pair(level[u], u);
  for (int v : G[u]) {
    level[v] = level[u] + 1, dfs(v);
    tour[0][++tourTime] = make_pair(level[u], u);
  }
}
int lca(int u, int v) {
  int l = min(pos[u], pos[v]);
  int r = max(pos[u], pos[v]);
  int dis = Log2[r - l + 1];
  return min(tour[dis][l], tour[dis][r - (1 << dis) + 1]).second;
}
pair<int, int> t[N << 2];
pair<int, int> Merge(pair<int, int> a, pair<int, int> b) {
  if (a == make_pair(0, 0)) return b;
  if (b == make_pair(0, 0)) return a;
  vector<int> v;
  v.reserve(7);
  v.emplace_back(a.first), v.emplace_back(a.second);
  v.emplace_back(b.first), v.emplace_back(b.second);
  sort(v.begin(), v.end(), [&](int a, int b) { return pos[a] < pos[b]; });
  v.erase(unique(v.begin(), v.end()), v.end());
  int n = (int)v.size();
  for (int i = 1; i < n; ++i) v.emplace_back(lca(v[i], v[i - 1]));
  sort(v.begin(), v.end(), [&](int a, int b) { return pos[a] < pos[b]; });
  v.erase(unique(v.begin(), v.end()), v.end());
  for (auto x : v) G[x].clear();
  for (int i = 1; i < (int)v.size(); ++i)
    G[lca(v[i], v[i - 1])].emplace_back(v[i]);
  for (int i = 1; i < (int)v.size(); ++i)
    if (G[v[i]].size() > 1) return make_pair(-1, -1);
  if (G[v[0]].size() > 2) return make_pair(-1, -1);
  pair<int, int> Ans = make_pair(-1, -1);
  for (auto x : v)
    if (G[x].size() == 0)
      if (~Ans.first)
        Ans.second = x;
      else
        Ans.first = x;
  if (Ans.second == -1) Ans.second = (v.size() > 1) ? v[0] : Ans.first;
  return Ans;
}
int label[N];
void Init(int node, int l, int r) {
  if (l == r) {
    t[node] = pair<int, int>(label[l], label[l]);
    return;
  }
  Init(node << 1, l, ((l + r) >> 1));
  Init(node << 1 | 1, ((l + r) >> 1) + 1, r);
  t[node] = Merge(t[node << 1], t[node << 1 | 1]);
}
void update(int node, int l, int r, int pos, int val) {
  if (pos < l || r < pos) return;
  if (l == r && l == pos) {
    t[node] = pair<int, int>(val, val);
    return;
  }
  update(node << 1, l, ((l + r) >> 1), pos, val);
  update(node << 1 | 1, ((l + r) >> 1) + 1, r, pos, val);
  t[node] = Merge(t[node << 1], t[node << 1 | 1]);
}
int trav(int node, int l, int r, pair<int, int> val) {
  pair<int, int> cur = Merge(t[node], val);
  if (~cur.first) return r;
  if (l == r) return l - 1;
  int k = trav(node << 1, l, ((l + r) >> 1), val);
  return (k < ((l + r) >> 1)) ? k
                              : (trav(node << 1 | 1, ((l + r) >> 1) + 1, r,
                                      Merge(val, t[node << 1])));
}
int p[N];
int main() {
  Log2[1] = 0;
  for (int i = 2; i < (N << 1); ++i) Log2[i] = Log2[i >> 1] + 1;
  int n = read();
  for (int i = 1; i <= n; ++i) p[i] = read(), label[p[i]] = i;
  for (int i = 2; i <= n; ++i) G[read()].emplace_back(i);
  dfs(1);
  for (int i = 1; i <= n; ++i) G[i].clear();
  for (int j = 1; j < 19; ++j)
    for (int i = 1; i + (1 << j) - 1 < (n << 1); ++i)
      tour[j][i] = min(tour[j - 1][i], tour[j - 1][i + (1 << (j - 1))]);
  Init(1, 0, n - 1);
  for (int q = read(); q-- > 0;) {
    int type = read();
    if (type == 1) {
      int a = read(), b = read();
      update(1, 0, n - 1, p[a], b);
      update(1, 0, n - 1, p[b], a);
      swap(p[a], p[b]);
    } else
      printf("%d\n", trav(1, 0, n - 1, pair<int, int>(0, 0)) + 1);
  }
}
