#include <bits/stdc++.h>
using namespace std;
const int maxn = 200500;
int p[maxn];
int q[maxn];
int d[maxn][19];
vector<int> edge[maxn];
int tin[maxn];
int tout[maxn];
pair<int, int> path[4 * maxn];
int ct = 0;
void dfs(int u) {
  tin[u] = ct++;
  for (auto v : edge[u]) {
    dfs(v);
  }
  tout[u] = ct++;
}
bool par(int u, int v) { return (tin[u] > tin[v] && tout[u] < tout[v]); }
int lca(int u, int v) {
  if (par(u, v)) return v;
  if (par(v, u)) return u;
  for (int i = 18; i >= 0; i--) {
    if (!par(u, d[v][i])) {
      v = d[v][i];
    }
  }
  v = d[v][0];
  return v;
}
pair<int, int> add_to_path(pair<int, int> p, int nx) {
  int u = p.first;
  int v = p.second;
  if (u == -1 || nx == -1) {
    return {-1, -1};
  }
  if (par(u, v)) {
    swap(u, v);
  }
  if (par(v, u) || v == u) {
    if (par(v, nx) || v == nx) {
      if (par(u, nx) || u == nx) {
        return {v, nx};
      }
      return p;
    } else {
      if (par(nx, v) || nx == v) {
        return {nx, u};
      }
      if (par(lca(nx, v), u)) {
        return {-1, -1};
      }
      return {v, nx};
    }
  }
  int l = lca(u, v);
  if (par(l, nx)) {
    return {-1, -1};
  }
  if (par(v, nx) || par(u, nx) || v == nx || u == nx) {
    return p;
  }
  if (par(nx, v)) {
    return {nx, u};
  }
  if (par(nx, u)) {
    return {v, nx};
  }
  return {-1, -1};
}
pair<int, int> merge_path(pair<int, int> p1, pair<int, int> p2) {
  auto p = add_to_path(add_to_path(p1, p2.first), p2.second);
  return p;
}
void init(int l, int r, int i) {
  if (l == r - 1) {
    path[i].first = path[i].second = q[l];
    return;
  }
  int m = (l + r) / 2;
  init(l, m, 2 * i + 1);
  init(m, r, 2 * i + 2);
  path[i] = merge_path(path[2 * i + 1], path[2 * i + 2]);
}
void change(int pos, int l, int r, int i) {
  if (l == r - 1) {
    path[i].first = path[i].second = q[l];
    return;
  }
  int m = (l + r) / 2;
  if (pos < m) {
    change(pos, l, m, 2 * i + 1);
  } else {
    change(pos, m, r, 2 * i + 2);
  }
  path[i] = merge_path(path[2 * i + 1], path[2 * i + 2]);
}
int gt(pair<int, int> p, int l, int r, int i) {
  if (l == r - 1) {
    p = merge_path(p, path[i]);
    if (p.first != -1) return l;
    return l - 1;
  }
  int m = (l + r) / 2;
  auto p1 = merge_path(p, path[2 * i + 1]);
  if (p1.first == -1) return gt(p, l, m, 2 * i + 1);
  return gt(p1, m, r, 2 * i + 2);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    q[p[i]] = i;
  }
  for (int i = 1; i < n; i++) {
    cin >> d[i][0];
    d[i][0]--;
    edge[d[i][0]].push_back(i);
    for (int j = 1; j < 19; j++) {
      d[i][j] = d[d[i][j - 1]][j - 1];
    }
  }
  dfs(0);
  init(0, n, 0);
  int que;
  cin >> que;
  while (que--) {
    int t;
    cin >> t;
    if (t == 1) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      swap(q[p[a]], q[p[b]]);
      swap(p[a], p[b]);
      change(p[a], 0, n, 0);
      change(p[b], 0, n, 0);
    } else {
      cout << gt({q[0], q[0]}, 0, n, 0) + 1 << "\n";
      ;
    }
  }
  return 0;
}
