#include <bits/stdc++.h>
int rmq[18 + 1][2 * 200000], lg[2 * 200000], e[2 * 200000];
int l[200000 + 1], r[200000 + 1], t[200000 + 1], h[200000 + 1];
std::vector<int> g[200000 + 1];
int poz[200000 + 1], poz1, poz2, mex, k, v[200000 + 1], p[200000 + 1];
struct myc {
  bool f;
  int a;
  int b;
  int t;
} ans, aux, aint[530000];
inline int lca(int a, int b) {
  a = poz[a];
  b = poz[b];
  if (a > b) std::swap(a, b);
  int l = lg[b - a + 1];
  if (h[rmq[l][b]] < h[rmq[l][a + (1 << l) - 1]])
    return rmq[l][b];
  else
    return rmq[l][a + (1 << l) - 1];
}
inline void combina(myc x, myc y, myc &z) {
  z = {0, 0, 0, 0};
  if (x.f || y.f) {
    z.f = 1;
    return;
  }
  if (x.a == 0 || y.a == 0) {
    if (x.a == 0)
      z = y;
    else
      z = x;
    return;
  }
  if (l[x.a] < l[y.a]) std::swap(x, y);
  if (r[x.a] < r[y.a]) {
    z.a = x.a;
    if (x.b == 0)
      z.b = y.b;
    else if (y.b == 0)
      z.b = x.b;
    else if (l[x.b] < l[y.b]) {
      if (r[x.b] > r[y.b])
        z.b = y.b;
      else {
        z.f = 1;
        return;
      }
    } else if (r[x.b] < r[y.b])
      z.b = x.b;
    else {
      z.f = 1;
      return;
    }
  } else {
    z.a = y.a;
    if (x.b) {
      z.f = 1;
      return;
    }
    if (y.b == 0)
      z.b = x.a;
    else if (l[x.a] < l[y.b]) {
      if (r[x.a] > r[y.b])
        z.b = y.b;
      else {
        z.f = 1;
        return;
      }
    } else if (r[x.a] < r[y.b])
      z.b = x.a;
    else {
      z.f = 1;
      return;
    }
  }
  if (l[x.t] < l[y.t])
    z.t = x.t;
  else
    z.t = y.t;
  if (z.b && h[z.t] < h[lca(z.a, z.b)]) z.f = 1;
}
void query(int p, int st, int dr) {
  if (st == mex) {
    combina(ans, aint[p], aux);
    if (aux.f == 0) {
      ans = aux;
      mex = dr + 1;
    } else if (st < dr) {
      int m = (st + dr) / 2;
      query(2 * p, st, m);
      query(2 * p + 1, m + 1, dr);
    }
  }
}
void defeseu(int p, int st, int dr) {
  if (st == dr)
    aint[p] = {0, v[st], 0, v[st]};
  else {
    int m = (st + dr) / 2;
    defeseu(2 * p, st, m);
    defeseu(2 * p + 1, m + 1, dr);
    combina(aint[2 * p], aint[2 * p + 1], aint[p]);
  }
}
void update(int p, int st, int dr) {
  if ((st > poz1 || poz1 > dr) && (st > poz2 || poz2 > dr)) return;
  if (st == dr)
    aint[p] = {0, v[st], 0, v[st]};
  else {
    int m = (st + dr) / 2;
    update(2 * p, st, m);
    update(2 * p + 1, m + 1, dr);
    combina(aint[2 * p], aint[2 * p + 1], aint[p]);
  }
}
void dfs(int x) {
  l[x] = ++k;
  e[++e[0]] = x;
  poz[x] = e[0];
  for (auto &y : g[x]) {
    h[y] = h[x] + 1;
    dfs(y);
    e[++e[0]] = x;
  }
  r[x] = ++k;
}
int main() {
  int n;
  fscanf(stdin, "%d", &n);
  for (int i = 1; i <= n; i++) {
    fscanf(stdin, "%d", &p[i]);
    v[p[i]] = i;
  }
  for (int i = 2; i <= n; i++) {
    fscanf(stdin, "%d", &t[i]);
    g[t[i]].push_back(i);
  }
  l[0] = 0;
  dfs(1);
  r[0] = k + 1;
  for (int i = 1; i <= e[0]; i++) {
    rmq[0][i] = e[i];
    if ((2 << lg[i - 1]) == i)
      lg[i] = lg[i - 1] + 1;
    else
      lg[i] = lg[i - 1];
  }
  for (int i = 1; i <= lg[e[0]]; i++)
    for (int j = 1 << i; j <= e[0]; j++)
      if (h[rmq[i - 1][j]] < h[rmq[i - 1][j - (1 << (i - 1))]])
        rmq[i][j] = rmq[i - 1][j];
      else
        rmq[i][j] = rmq[i - 1][j - (1 << (i - 1))];
  defeseu(1, 0, n - 1);
  int q;
  fscanf(stdin, "%d", &q);
  for (int i = 1; i <= q; i++) {
    int t;
    fscanf(stdin, "%d", &t);
    if (t == 1) {
      int x, y;
      fscanf(stdin, "%d%d", &x, &y);
      poz1 = p[x];
      poz2 = p[y];
      v[p[x]] = y;
      v[p[y]] = x;
      std::swap(p[x], p[y]);
      update(1, 0, n - 1);
    } else {
      ans = {0, 0, 0, 0};
      mex = 0;
      query(1, 0, n - 1);
      fprintf(stdout, "%d\n", mex);
    }
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
