#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 200033;
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) f = c == '-' ? -1 : 1, c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long ksm(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, q, ans;
int a[mxn], in[mxn], out[mxn], dep[mxn], dfn;
int lg[mxn], f[21][mxn];
vector<int> g[mxn];
void dfs(int u, int pre) {
  in[u] = ++dfn;
  f[0][u] = pre;
  dep[u] = dep[pre] + 1;
  for (int i = 1; i <= lg[dep[u]]; i++) f[i][u] = f[i - 1][f[i - 1][u]];
  for (auto v : g[u]) {
    if (v != pre) dfs(v, u);
  }
  out[u] = ++dfn;
}
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  while (dep[y] > dep[x]) y = f[lg[dep[y] - dep[x]] - 1][y];
  if (y == x) return x;
  for (int i = lg[dep[x]] - 1; i >= 0; i--) {
    if (f[i][x] != f[i][y]) {
      x = f[i][x];
      y = f[i][y];
    }
  }
  return f[0][x];
}
namespace Segment {
pair<int, int> t[mxn << 2], res;
bool anc(int x, int y) { return in[x] <= in[y] && out[x] >= out[y]; }
pair<int, int> check(pair<int, int> x, int y) {
  if (!x.first || !y) return make_pair(0, 0);
  if (anc(x.first, x.second)) swap(x.first, x.second);
  if (anc(x.second, x.first)) {
    if (anc(x.first, y)) return make_pair(x.second, y);
    if (anc(x.second, y)) {
      if (anc(y, x.first)) return x;
      if (lca(x.first, y) == x.second) return make_pair(x.first, y);
      return make_pair(0, 0);
    }
    return make_pair(y, x.first);
  }
  if (anc(x.first, y)) return make_pair(y, x.second);
  if (anc(x.second, y)) return make_pair(y, x.first);
  if (!anc(y, x.first) && !anc(y, x.second)) return make_pair(0, 0);
  if (!anc(lca(x.first, x.second), y)) return make_pair(0, 0);
  return x;
}
pair<int, int> merge(pair<int, int> x, pair<int, int> y) {
  if (x.first == -1) return y;
  x = check(x, y.first);
  x = check(x, y.second);
  return x;
}
void update(int x, int l, int r, int p, int v) {
  if (l == r) {
    t[x] = make_pair(v, v);
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    update((x << 1), l, mid, p, v);
  else
    update((x << 1 | 1), mid + 1, r, p, v);
  t[x] = merge(t[(x << 1)], t[(x << 1 | 1)]);
}
bool query(int x, int l, int r) {
  pair<int, int> tmp = merge(res, t[x]);
  if (tmp.first) {
    res = tmp;
    ans = r;
    return 1;
  }
  if (l == r) return 0;
  int mid = (l + r) >> 1;
  if (query((x << 1), l, mid)) query((x << 1 | 1), mid + 1, r);
  return 0;
}
};  // namespace Segment
using namespace Segment;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += 1;
  }
  for (int i = 2; i <= n; ++i) {
    int x;
    cin >> x;
    g[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);
  dfn = 0;
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) update(1, 1, n, a[i], i);
  cin >> q;
  int opt, x, y;
  while (q--) {
    cin >> opt;
    if (opt & 1) {
      cin >> x >> y;
      swap(a[x], a[y]);
      update(1, 1, n, a[x], x);
      update(1, 1, n, a[y], y);
    } else {
      res = make_pair(-1, 0), ans = 0;
      query(1, 1, n);
      cout << ans << endl;
    }
  }
  return 0;
}
