#include <bits/stdc++.h>
using namespace std;
template <typename T>
void clear(T& t) {
  t.clear();
}
template <typename T, typename... Ts>
void clear(T& t, Ts&... ts) {
  t.clear();
  clear(ts...);
}
template <typename T>
void clearAndResize(int n, T& t) {
  t.clear();
  t.resize(n);
}
template <typename T, typename... Ts>
void clearAndResize(int n, T& t, Ts&... ts) {
  t.clear();
  t.resize(n);
  clearAndResize(n, ts...);
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  for (auto a : v) o << a << " ";
  return o;
}
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << ", " << p.second << ") ";
  return o;
}
vector<int> perm;
const int LOG = 20;
vector<vector<int> > tree;
vector<int> depth;
vector<int> inTime, outTime;
vector<vector<pair<int, int> > > lcaTable;
vector<int> logg;
void resizeLCA(int n) {
  clearAndResize(n, tree, depth, inTime, outTime, logg);
  clearAndResize(LOG, lcaTable);
  lcaTable[0].reserve(2 * n + 1);
}
void lcaDfs(int cur, int p, int d) {
  inTime[cur] = lcaTable[0].size();
  depth[cur] = d;
  lcaTable[0].push_back({d, cur});
  for (auto a : tree[cur]) {
    if (a != p) {
      lcaDfs(a, cur, d + 1);
      lcaTable[0].push_back({d, cur});
    }
  }
  outTime[cur] = lcaTable[0].size() - 1;
}
void buildLcaTable() {
  lcaDfs(0, 0, 0);
  int pot = 1, potl = 0;
  logg.resize(lcaTable[0].size() + 1);
  for (int i = 1; i < logg.size(); i++) {
    while (pot * 2 <= i) {
      pot *= 2;
      potl++;
    }
    logg[i] = potl;
  }
  for (int i = 1, pot = 1; i < lcaTable.size(); i++, pot *= 2) {
    lcaTable[i].resize(lcaTable[0].size());
    for (int j = 0; j < lcaTable[i].size(); j++) {
      if (j + pot < lcaTable[i - 1].size())
        lcaTable[i][j] = min(lcaTable[i - 1][j], lcaTable[i - 1][j + pot]);
      else
        lcaTable[i][j] = lcaTable[i - 1][j];
    }
  }
}
int lca(int a, int b) {
  int ac = min(inTime[a], inTime[b]);
  int bc = max(outTime[a], outTime[b]);
  int l = logg[bc - ac + 1];
  return min(lcaTable[l][ac], lcaTable[l][bc - (1 << l) + 1]).second;
}
const int SIZ = (1 << LOG);
pair<int, int> seg[2 * SIZ];
int isInSubtree(int a, int s) {
  return inTime[a] <= inTime[s] && outTime[a] >= outTime[s];
}
pair<int, int> checkp(int a, int b, int u, int v) {
  int l = lca(a, b);
  if (!isInSubtree(l, u) || !isInSubtree(l, v)) return {-1, -1};
  if ((isInSubtree(u, a) || isInSubtree(u, b)) &&
      (isInSubtree(v, a) || isInSubtree(v, b)))
    return {a, b};
  return {-1, -1};
}
pair<int, int> check(pair<int, int> a, pair<int, int> b) {
  if (a.first == -1 || b.first == -1) return {-1, -1};
  if (depth[a.first] < depth[a.second]) swap(a.first, a.second);
  if (depth[b.first] < depth[b.second]) swap(b.first, b.second);
  if (depth[a.first] < depth[b.first]) swap(a, b);
  pair<int, int> res;
  res = checkp(a.first, a.second, b.first, b.second);
  if (res.first != -1) return res;
  res = checkp(a.first, b.first, a.second, b.second);
  if (res.first != -1) return res;
  res = checkp(a.first, b.second, b.first, a.second);
  return res;
}
void update(int a, int v) {
  a += SIZ + 1;
  seg[a] = {v, v};
  a /= 2;
  while (a > 0) {
    auto l = seg[2 * a];
    auto r = seg[2 * a + 1];
    seg[a] = check(l, r);
    a /= 2;
  }
}
int query() {
  int a = SIZ;
  pair<int, int> cur = seg[a + 1];
  while (a > 0) {
    if (a % 2 == 0) {
      auto cp = check(cur, seg[a + 1]);
      if (cp.first == -1) {
        a++;
        break;
      } else {
        cur = cp;
      }
    }
    a /= 2;
  }
  while (a < SIZ) {
    auto cp = check(cur, seg[2 * a]);
    if (cp.first == -1) {
      a *= 2;
    } else {
      a = a * 2 + 1;
      cur = cp;
    }
  }
  if (check(cur, seg[a]).first != -1)
    return a - SIZ;
  else
    return a - SIZ - 1;
}
int32_t main(int argv, char** argc) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  resizeLCA(n);
  perm.resize(n);
  for (int i = 0; i < n; i++) cin >> perm[i];
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    tree[i].push_back(p - 1);
    tree[p - 1].push_back(i);
  }
  buildLcaTable();
  for (int i = 0; i < 2 * SIZ; i++) seg[i] = {-1, -1};
  for (int i = 0; i < n; i++) update(perm[i], i);
  int q;
  cin >> q;
  while (q--) {
    int c;
    cin >> c;
    if (c == 1) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      update(perm[a], -1);
      update(perm[b], -1);
      swap(perm[a], perm[b]);
      update(perm[a], a);
      update(perm[b], b);
    } else {
      cout << query() << "\n";
    }
  }
}
