#include <bits/stdc++.h>
int hmt() {
  int x = 0;
  int c = getchar(), n = 0;
  for (; !isdigit(c); c = getchar()) n = (c == '-');
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  if (n) x = -x;
  return x;
}
using namespace std;
const int maxn = 2e5 + 5;
int N, Q, tin[maxn], tout[maxn], depth[maxn];
vector<int> adj[maxn];
int par[maxn][20], a[maxn], pos[maxn];
void prepare(int u = 1, int p = -1) {
  for (int i = 1; (1 << i) <= N; ++i) {
    par[u][i] = par[par[u][i - 1]][i - 1];
  }
  static int Time = 0;
  tin[u] = ++Time;
  for (auto v : adj[u])
    if (v != p) {
      par[v][0] = u;
      depth[v] = depth[u] + 1;
      prepare(v, u);
    }
  tout[u] = Time;
}
bool Par(int u, int v) { return tin[u] <= tin[v] && tout[v] <= tout[u]; }
int LCA(int x, int y) {
  if (depth[x] < depth[y]) swap(x, y);
  if (Par(y, x)) return y;
  for (int k = 19; k >= 0; --k) {
    if (depth[par[x][k]] >= depth[y]) {
      x = par[x][k];
    }
  }
  if (x == y) return x;
  for (int k = 19; k >= 0; --k) {
    if (par[x][k] != par[y][k]) {
      x = par[x][k];
      y = par[y][k];
    }
  }
  return par[x][0];
}
int Son(int u, int v) {
  int dist = depth[v] - depth[u] - 1;
  for (int i = 19; i >= 0; --i) {
    if (dist >> i & 1) {
      v = par[v][i];
    }
  }
  return v;
}
bool check(pair<int, int> p1, pair<int, int> p2) {
  if (depth[p2.first] < depth[p2.second]) swap(p2.first, p2.second);
  if (Par(p2.first, p1.second)) swap(p1.first, p1.second);
  if (Par(p2.first, p1.first)) {
    if (Par(p2.second, p2.first)) {
      if (!Par(p2.second, p1.second) || p2.second == p1.second)
        return true;
      else {
        if (Son(p2.second, p1.first) == Son(p2.second, p1.second))
          return false;
        else
          return true;
      }
    } else {
      return Par(p2.second, p1.second);
    }
  } else
    return false;
}
struct Node {
  int u, v, ok;
} ST[4 * maxn];
Node operator+(const Node& a, const Node& oth) {
  int u = a.u, v = a.v, ok = a.ok;
  Node res;
  res.ok = min(ok, oth.ok);
  if (res.ok == 0) {
    return res;
  }
  if (u == 0) {
    return res = oth;
  }
  if (oth.u == 0) {
    return res = a;
  }
  vector<int> vi = {u, v, oth.u, oth.v};
  sort(vi.begin(), vi.end());
  vi.erase(unique(vi.begin(), vi.end()), vi.end());
  for (int i = 0; i < (int)vi.size(); ++i) {
    for (int j = i + 1; j < (int)vi.size(); ++j) {
      pair<int, int> need = make_pair(vi[i], vi[j]);
      if (check(need, make_pair(u, v)) &&
          check(need, make_pair(oth.u, oth.v))) {
        tie(res.u, res.v) = need;
        res.ok = true;
        return res;
      }
    }
  }
  res.ok = false;
  return res;
}
void dbg(Node x) { cerr << x.u << ' ' << x.v << ' ' << x.ok; }
void build(int id, int l, int r) {
  if (l == r) {
    ST[id].ok = 1;
    ST[id].u = ST[id].v = pos[l];
    return;
  }
  int mid = (l + r) / 2;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  ST[id] = ST[id << 1] + ST[id << 1 | 1];
}
void update(int pos, int val, int id = 1, int l = 0, int r = N - 1) {
  if (pos < l || pos > r) return;
  if (l == r) {
    ST[id].ok = 1;
    ST[id].u = ST[id].v = val;
    return;
  }
  int mid = (l + r) / 2;
  update(pos, val, id << 1, l, mid);
  update(pos, val, id << 1 | 1, mid + 1, r);
  ST[id] = ST[id << 1] + ST[id << 1 | 1];
}
void pri(int id = 1, int l = 0, int r = N - 1) {
  cerr << l << ' ' << r << ' ';
  dbg(ST[id]);
  cerr << '\n';
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  pri(id << 1, l, mid);
  pri(id << 1 | 1, mid + 1, r);
}
int query(int id, int l, int r, Node now) {
  if (l == r) {
    Node nxt = now + ST[id];
    if (nxt.ok) return l;
    return -1;
  }
  int mid = (l + r) / 2;
  Node nxt = now + ST[id << 1];
  if (nxt.ok) {
    return max(mid, query(id << 1 | 1, mid + 1, r, nxt));
  } else {
    return query(id << 1, l, mid, now);
  }
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  N = hmt();
  for (int i = 1; i <= N; ++i) {
    a[i] = hmt();
    pos[a[i]] = i;
  }
  for (int i = 2; i <= N; ++i) {
    int p;
    p = hmt();
    adj[i].emplace_back(p);
    adj[p].emplace_back(i);
  }
  depth[1] = 1;
  prepare(1);
  build(1, 0, N - 1);
  Q = hmt();
  while (Q--) {
    int type;
    type = hmt();
    if (type == 1) {
      int u, v;
      u = hmt();
      v = hmt();
      update(a[u], v);
      update(a[v], u);
      swap(a[u], a[v]);
    } else {
      cout << query(1, 0, N - 1, {0, 0, 1}) + 1 << '\n';
    }
  }
}
