#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
const int N = 2e5 + 100;
int anc[N][20];
int v[N], deep[N];
vector<int> vc[N];
void dfs(int o) {
  for (int x : vc[o]) {
    deep[x] = deep[o] + 1;
    anc[x][0] = o;
    for (int i = 1; i < 19; ++i) anc[x][i] = anc[anc[x][i - 1]][i - 1];
    dfs(x);
  }
}
int lca(int u, int v) {
  if (deep[u] > deep[v]) swap(u, v);
  int k = deep[v] - deep[u];
  for (int i = 19; i >= 0; --i) {
    if ((k >> i) & 1) v = anc[v][i];
  }
  if (u == v) return u;
  for (int i = 19; i >= 0; --i) {
    if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];
  }
  return anc[u][0];
}
int ok[N << 2], pre[N << 2], type[N << 2], low[N << 2][2];
void Merge(int rt, int ls, int rs) {
  if (!ok[ls] || !ok[rs]) {
    ok[rt] = 0;
    return;
  }
  if (type[ls] + type[rs] == 2 && pre[ls] == low[ls][0] &&
      pre[rs] == low[rs][0]) {
    int fp = lca(pre[ls], pre[rs]);
    ok[rt] = 1;
    pre[rt] = fp;
    if (fp == pre[ls] || fp == pre[rs]) {
      type[rt] = 1;
      if (fp == low[ls][0])
        low[rt][0] = low[rs][0];
      else
        low[rt][0] = low[ls][0];
    } else {
      type[rt] = 2;
      low[rt][0] = pre[ls];
      low[rt][1] = pre[rs];
    }
    return;
  }
  if (pre[ls] == low[ls][0]) swap(ls, rs);
  if (type[ls] == 1 && type[rs] == 1 && pre[rs] == low[rs][0]) {
    int fp = lca(pre[ls], pre[rs]);
    int sp = lca(low[ls][0], low[rs][0]);
    pre[rt] = fp;
    if (fp == sp) {
      if (fp == pre[rs]) {
        ok[rt] = 1;
        type[rt] = 1;
        low[rt][0] = low[ls][0];
        pre[rt] = fp;
      } else {
        ok[rt] = 1;
        type[rt] = 2;
        low[rt][0] = low[ls][0];
        low[rt][1] = low[rs][0];
        pre[rt] = fp;
      }
    } else if ((fp == pre[ls] || fp == pre[rs]) &&
               (sp == low[ls][0] || sp == low[rs][0])) {
      ok[rt] = 1;
      type[rt] = 1;
      if (sp == low[ls][0])
        low[rt][0] = low[rs][0];
      else
        low[rt][0] = low[ls][0];
    } else
      ok[rt] = 0;
    return;
  }
  if (type[ls] == 1 && type[rs] == 1) {
    int fp = lca(pre[ls], pre[rs]);
    int sp = lca(low[ls][0], low[rs][0]);
    pre[rt] = fp;
    if (fp == sp) {
      type[rt] = 2;
      ok[rt] = 1;
      low[rt][0] = low[ls][0];
      low[rt][1] = low[rs][0];
    } else if ((fp == pre[ls] || fp == pre[rs]) &&
               (sp == low[ls][0] || sp == low[rs][0])) {
      ok[rt] = 1;
      type[rt] = 1;
      if (sp == low[ls][0])
        low[rt][0] = low[rs][0];
      else
        low[rt][0] = low[ls][0];
    } else
      ok[rt] = 0;
    return;
  }
  if (type[ls] + type[rs] == 3) {
    if (type[ls] == 2) swap(ls, rs);
    int fp = lca(pre[ls], pre[rs]);
    if (fp != pre[rs])
      ok[rt] = 0;
    else {
      type[rt] = 2;
      pre[rt] = fp;
      int sp = lca(low[ls][0], low[rs][0]);
      if (sp == low[ls][0]) {
        low[rt][0] = low[rs][0];
        low[rt][1] = low[rs][1];
        ok[rt] = 1;
        return;
      }
      if (sp == low[rs][0]) {
        low[rt][0] = low[ls][0];
        low[rt][1] = low[rs][1];
        ok[rt] = 1;
        return;
      }
      sp = lca(low[ls][0], low[rs][1]);
      if (sp == low[ls][0]) {
        low[rt][0] = low[rs][0];
        low[rt][1] = low[rs][1];
        ok[rt] = 1;
        return;
      }
      if (sp == low[rs][1]) {
        low[rt][0] = low[rs][0];
        low[rt][1] = low[ls][0];
        ok[rt] = 1;
        return;
      }
      ok[rt] = 0;
      return;
    }
    return;
  }
  if (type[ls] + type[rs] == 4) {
    type[rt] = 2;
    if (pre[ls] == pre[rs]) {
      pre[rt] = pre[ls];
      int sp1 = lca(low[ls][0], low[rs][0]), sp2 = lca(low[ls][1], low[rs][1]);
      if ((sp1 == low[ls][0] || sp1 == low[rs][0]) &&
          (sp2 == low[ls][1] || sp2 == low[rs][1])) {
        ok[rt] = 1;
        if (sp1 == low[ls][0])
          low[rt][0] = low[rs][0];
        else
          low[rt][0] = low[ls][0];
        if (sp2 == low[ls][1])
          low[rt][1] = low[rs][1];
        else
          low[rt][1] = low[ls][1];
        return;
      }
      sp1 = lca(low[ls][0], low[rs][1]), sp2 = lca(low[ls][1], low[rs][0]);
      if ((sp1 == low[ls][0] || sp1 == low[rs][1]) &&
          (sp2 == low[ls][1] || sp2 == low[rs][0])) {
        ok[rt] = 1;
        if (sp1 == low[ls][0])
          low[rt][0] = low[rs][1];
        else
          low[rt][0] = low[ls][0];
        if (sp2 == low[ls][1])
          low[rt][1] = low[rs][0];
        else
          low[rt][1] = low[ls][1];
        return;
      }
      ok[rt] = 0;
    } else
      ok[rt] = 0;
  }
  ok[rt] = 0;
}
void Update(int L, int k, int l, int r, int rt) {
  if (l == r) {
    ok[rt] = 1;
    pre[rt] = k;
    low[rt][0] = k;
    type[rt] = 1;
    return;
  }
  int m = l + r >> 1;
  if (L <= m)
    Update(L, k, l, m, rt << 1);
  else
    Update(L, k, m + 1, r, rt << 1 | 1);
  Merge(rt, rt << 1, rt << 1 | 1);
}
void Copy(int aim, int f) {
  ok[aim] = ok[f];
  pre[aim] = pre[f];
  low[aim][0] = low[f][0];
  low[aim][1] = low[f][1];
  type[aim] = type[f];
}
int n, u;
int to = (200000 << 2) + 10, b = 0, ansr;
void qqq(int k) {
  cout << ok[k] << ' ' << pre[k] << ' ' << low[k][0] << ' ' << low[k][1] << ' '
       << type[k] << endl;
  ;
}
int Query(int l, int r, int rt) {
  if (ok[rt]) {
    if (b == 0) {
      b = to;
      ansr = r;
      Copy(b, rt);
      return 1;
    } else {
      Merge(to + 1, to, rt);
      if (ok[to + 1]) {
        Copy(to, to + 1);
        ansr = r;
        return 1;
      } else {
        if (l != r) {
          int m = l + r >> 1;
          int k = Query(l, m, rt << 1);
          if (k == 1) Query(m + 1, r, rt << 1 | 1);
        }
        return 0;
      }
    }
  }
  int m = l + r >> 1;
  if (l == r) return 0;
  int k = Query(l, m, rt << 1);
  if (k == 1) Query(m + 1, r, rt << 1 | 1);
  return 0;
}
void solve(int l, int r, int rt) {
  cout << l << " with " << r << " :\n";
  qqq(rt);
  if (l == r) return;
  int m = l + r >> 1;
  solve(l, m, rt << 1);
  solve(m + 1, r, rt << 1 | 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &v[i]), v[i] += 1;
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &u);
    vc[u].push_back(i);
  }
  dfs(1);
  for (int i = 1; i <= n; ++i) Update(v[i], i, 1, n, 1);
  int q, op, l, r;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &l, &r);
      swap(v[l], v[r]);
      Update(v[l], l, 1, n, 1);
      Update(v[r], r, 1, n, 1);
    } else {
      b = 0;
      Query(1, n, 1);
      printf("%d\n", ansr);
    }
  }
  return 0;
}
