#include <bits/stdc++.h>
using namespace std;
int p[200005];
int locate[200005];
vector<int> v[200005];
int in[200005];
int out[200005];
int t;
int pa[200005][20];
int dep[200005];
void dfs(int first, int f) {
  pa[first][0] = f;
  in[first] = ++t;
  dep[first] = dep[f] + 1;
  for (auto it : v[first]) {
    if (it != f) {
      dfs(it, first);
    }
  }
  out[first] = ++t;
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19; i >= 0; i--) {
    if (dep[pa[u][i]] >= dep[v]) u = pa[u][i];
  }
  if (u == v) return v;
  for (int i = 19; i >= 0; i--) {
    if (pa[u][i] != pa[v][i]) {
      u = pa[u][i];
      v = pa[v][i];
    }
  }
  return pa[u][0];
}
struct node {
  node *l, *r;
  int a, b;
  pair<int, int> path;
  node(int _a, int _b) : l(NULL), r(NULL) {
    a = _a, b = _b;
    path = make_pair((-1), (-1));
  }
} * root;
bool cmp(const int &a, const int &b) { return in[a] < in[b]; }
pair<int, int> merge(int a, int b, int c) {
  if (a == -1 || b == -1 || c == -1) {
    return make_pair((-1), (-1));
  }
  vector<int> v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  sort(v.begin(), v.end(), cmp);
  if (in[v[1]] <= out[v[0]] && in[v[2]] <= out[v[1]]) {
    return make_pair((v[0]), (v[2]));
  }
  if (in[v[1]] <= out[v[0]]) {
    int first = lca(v[1], v[2]);
    if (in[v[0]] <= out[first] && in[first] <= in[v[0]]) {
      return make_pair((v[1]), (v[2]));
    }
  } else if (in[v[2]] <= out[v[1]]) {
    int first = lca(v[0], v[2]);
    if (in[v[1]] <= out[first] && in[first] <= in[v[1]]) {
      return make_pair((v[0]), (v[2]));
    }
  }
  return make_pair((-1), (-1));
}
void pull(node *n) {
  pair<int, int> p1 = n->l->path;
  pair<int, int> p2 = n->r->path;
  if (p1 == make_pair((-1), (-1)) || p2 == make_pair((-1), (-1))) {
    n->path = make_pair((-1), (-1));
  } else {
    pair<int, int> pp = merge(p1.first, p1.second, p2.first);
    n->path = merge(pp.first, pp.second, p2.second);
  }
}
void build(node *n = root) {
  if (n->a == n->b) {
    n->path = make_pair((locate[n->a]), (locate[n->b]));
    return;
  }
  int mid = (n->a + n->b) / 2;
  n->l = new node(n->a, mid);
  n->r = new node(mid + 1, n->b);
  build(n->l);
  build(n->r);
  pull(n);
}
void revise(node *n, int first) {
  if (n->a == n->b) {
    n->path = make_pair((locate[n->a]), (locate[n->b]));
    return;
  }
  int mid = (n->a + n->b) / 2;
  if (first <= mid)
    revise(n->l, first);
  else
    revise(n->r, first);
  pull(n);
}
int query() {
  node *n = root;
  if (root->path != make_pair((-1), (-1))) return root->b;
  while (n->l->path == make_pair((-1), (-1))) n = n->l;
  int res = n->l->b;
  pair<int, int> path = n->l->path;
  n = n->r;
  while (n && n->l) {
    pair<int, int> pp = n->l->path;
    pair<int, int> p1 = merge(path.first, path.second, pp.first);
    p1 = merge(p1.first, p1.second, pp.second);
    if (p1 != make_pair((-1), (-1))) {
      path = p1;
      res = n->l->b;
      n = n->r;
    } else {
      n = n->l;
    }
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]), locate[p[i]] = i;
  for (int i = 2; i <= n; i++) {
    int first;
    scanf("%d", &first);
    v[first].push_back(i);
  }
  dfs(1, 0);
  root = new node(0, n - 1);
  for (int i = 1; i < 20; i++) {
    for (int j = 1; j <= n; j++) {
      pa[j][i] = pa[pa[j][i - 1]][i - 1];
    }
  }
  build();
  int q;
  scanf("%d", &q);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int first, second;
      scanf("%d %d", &first, &second);
      swap(locate[p[first]], locate[p[second]]);
      swap(p[first], p[second]);
      revise(root, p[first]);
      revise(root, p[second]);
    } else {
      printf("%d\n", query() + 1);
    }
  }
}
