#include <bits/stdc++.h>
using namespace std;
inline int Getint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) ch != '-' ?: f = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
const int N = 200005;
int n, Q, cnt, top, h[N], a[N], dep[N], p[N * 2][20], dfn[N * 2], st[N * 2],
    id[N * 2], lg[N * 2];
struct edge {
  int to, next;
} e[N * 2];
void addedge(int x, int y) {
  e[++cnt] = (edge){y, h[x]};
  h[x] = cnt;
}
void dfs(int x, int fa) {
  st[++top] = x;
  dfn[x] = top;
  dep[x] = dep[fa] + 1;
  for (int i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    dfs(y, x);
    st[++top] = x;
  }
}
int LCA(int x, int y) {
  x = dfn[x];
  y = dfn[y];
  if (x > y) swap(x, y);
  int k = lg[y - x + 1];
  return dep[p[x][k]] < dep[p[y - (1 << k) + 1][k]] ? p[x][k]
                                                    : p[y - (1 << k) + 1][k];
}
struct line {
  int x, y;
  line(int a = 0, int b = 0) {
    x = a;
    y = b;
  }
} now;
bool judge(line a, int b) {
  int lca = LCA(a.x, a.y);
  return (LCA(a.x, b) == b || LCA(a.y, b) == b) && LCA(lca, b) == lca;
}
line merge(line a, line b) {
  if (a.x == -1) return a;
  if (b.x == -1) return b;
  if (!a.x) return b;
  if (!b.x) return a;
  int t[4] = {a.x, a.y, b.x, b.y};
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++) {
      bool FLAG = 1;
      for (int k = 0; k < 4 && FLAG; k++) FLAG &= judge(line(t[i], t[j]), t[k]);
      if (FLAG) return line(t[i], t[j]);
    }
  return line(-1, -1);
}
struct node {
  int l, r;
  line tmp;
} Tree[N * 4];
void pushup(int x) {
  Tree[x].tmp = merge(Tree[x * 2].tmp, Tree[x * 2 + 1].tmp);
}
void build(int x, int l, int r) {
  Tree[x] = (node){l, r};
  if (l == r) {
    if (l < n)
      Tree[x].tmp = line(id[l], id[l]);
    else
      Tree[x].tmp = line(-1, -1);
    return;
  }
  int mid = (l + r) >> 1;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  pushup(x);
}
void modify(int x, int pos) {
  if (Tree[x].l == Tree[x].r)
    return Tree[x].tmp = line(id[pos], id[pos]), void();
  int mid = (Tree[x].l + Tree[x].r) >> 1;
  if (pos <= mid)
    modify(x * 2, pos);
  else
    modify(x * 2 + 1, pos);
  pushup(x);
}
int query(int x) {
  if (Tree[x].l == Tree[x].r) return Tree[x].l;
  line tmp = merge(Tree[x * 2].tmp, now);
  if (tmp.x != -1) return now = tmp, query(x * 2 + 1);
  return query(x * 2);
}
int main() {
  lg[1] = 0;
  for (int i = 2; i <= 400000; i++) lg[i] = lg[i >> 1] + 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    id[a[i] = Getint()] = i;
  }
  for (int i = 2; i <= n; i++) addedge(Getint(), i);
  dfs(1, 0);
  for (int i = 1; i <= 2 * n; i++) p[i][0] = st[i];
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i + (1 << j) - 1 <= 2 * n; i++)
      if (dep[p[i][j - 1]] < dep[p[i + (1 << j - 1)][j - 1]])
        p[i][j] = p[i][j - 1];
      else
        p[i][j] = p[i + (1 << j - 1)][j - 1];
  build(1, 0, n);
  Q = Getint();
  while (Q--) {
    int op = Getint(), x, y;
    if (op == 1) {
      x = Getint();
      y = Getint();
      swap(id[a[x]], id[a[y]]);
      swap(a[x], a[y]);
      modify(1, a[x]);
      modify(1, a[y]);
    } else {
      now = line();
      cout << query(1) << "\n";
    }
  }
}

### Prompt

Construct a cpp code solution to the problem outlined:

Once Grisha found a tree (connected graph without cycles) with a root in node 1.

But this tree was not just a tree. A permutation p of integers from 0 to n - 1 is written in nodes, a number p_i is written in node i.

As Grisha likes to invent some strange and interesting problems for himself, but not always can solve them, you need to help him deal with two types of queries on this tree.

Let's define a function MEX(S), where S is a set of non-negative integers, as a smallest non-negative integer that is not included in this set.

Let l be a simple path in this tree. So let's define indices of nodes which lie on l as u_1, u_2, …, u_k. 

Define V(l) as a set {p_{u_1}, p_{u_2}, … , p_{u_k}}. 

Then queries are: 

  1. For two nodes i and j, swap p_i and p_j. 
  2. Find the maximum value of MEX(V(l)) in all possible l. 

Input

The first line contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of nodes of a tree.

The second line contains n integers — p_1, p_2, …, p_n (0≤ p_i < n) — the permutation p, it's guaranteed that all numbers are different .

The third line contains n - 1 integers — d_2, d_3, …, d_n (1 ≤ d_i < i), where d_i is a direct ancestor of node i in a tree.

The fourth line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

The following q lines contain the description of queries:

At the beginning of each of next q lines, there is a single integer t (1 or 2) — the type of a query: 

  1. If t = 1, the line also contains two integers i and j (1 ≤ i, j ≤ n) — the indices of nodes, where values of the permutation should be swapped. 
  2. If t = 2, you need to find the maximum value of MEX(V(l)) in all possible l. 

Output

For each type 2 query print a single integer — the answer for this query.

Examples

Input


6
2 5 0 3 1 4
1 1 3 3 3
3
2
1 6 3
2


Output


3
2


Input


6
5 2 1 4 3 0
1 1 1 3 3
9
2
1 5 3
2
1 6 1
2
1 4 2
2
1 1 6
2


Output


3
2
4
4
2

Note

Number written in brackets is a permutation value of a node. 

<image> In the first example, for the first query, optimal path is a path from node 1 to node 5. For it, set of values is \{0, 1, 2\} and MEX is 3.  <image> For the third query, optimal path is a path from node 5 to node 6. For it, set of values is \{0, 1, 4\} and MEX is 2.  <image> In the second example, for the first query, optimal path is a path from node 2 to node 6. For it, set of values is \{0, 1, 2, 5\} and MEX is 3.  <image> For the third query, optimal path is a path from node 5 to node 6. For it, set of values is \{0, 1, 3\} and MEX is 2.  <image> For the fifth query, optimal path is a path from node 5 to node 2. For it, set of values is \{0, 1, 2, 3\} and MEX is 4.  <image> For the seventh query, optimal path is a path from node 5 to node 4. For it, set of values is \{0, 1, 2, 3\} and MEX is 4.  <image> For the ninth query, optimal path is a path from node 6 to node 5. For it, set of values is \{0, 1, 3\} and MEX is 2. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int Getint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) ch != '-' ?: f = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
const int N = 200005;
int n, Q, cnt, top, h[N], a[N], dep[N], p[N * 2][20], dfn[N * 2], st[N * 2],
    id[N * 2], lg[N * 2];
struct edge {
  int to, next;
} e[N * 2];
void addedge(int x, int y) {
  e[++cnt] = (edge){y, h[x]};
  h[x] = cnt;
}
void dfs(int x, int fa) {
  st[++top] = x;
  dfn[x] = top;
  dep[x] = dep[fa] + 1;
  for (int i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    dfs(y, x);
    st[++top] = x;
  }
}
int LCA(int x, int y) {
  x = dfn[x];
  y = dfn[y];
  if (x > y) swap(x, y);
  int k = lg[y - x + 1];
  return dep[p[x][k]] < dep[p[y - (1 << k) + 1][k]] ? p[x][k]
                                                    : p[y - (1 << k) + 1][k];
}
struct line {
  int x, y;
  line(int a = 0, int b = 0) {
    x = a;
    y = b;
  }
} now;
bool judge(line a, int b) {
  int lca = LCA(a.x, a.y);
  return (LCA(a.x, b) == b || LCA(a.y, b) == b) && LCA(lca, b) == lca;
}
line merge(line a, line b) {
  if (a.x == -1) return a;
  if (b.x == -1) return b;
  if (!a.x) return b;
  if (!b.x) return a;
  int t[4] = {a.x, a.y, b.x, b.y};
  for (int i = 0; i < 4; i++)
    for (int j = i + 1; j < 4; j++) {
      bool FLAG = 1;
      for (int k = 0; k < 4 && FLAG; k++) FLAG &= judge(line(t[i], t[j]), t[k]);
      if (FLAG) return line(t[i], t[j]);
    }
  return line(-1, -1);
}
struct node {
  int l, r;
  line tmp;
} Tree[N * 4];
void pushup(int x) {
  Tree[x].tmp = merge(Tree[x * 2].tmp, Tree[x * 2 + 1].tmp);
}
void build(int x, int l, int r) {
  Tree[x] = (node){l, r};
  if (l == r) {
    if (l < n)
      Tree[x].tmp = line(id[l], id[l]);
    else
      Tree[x].tmp = line(-1, -1);
    return;
  }
  int mid = (l + r) >> 1;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  pushup(x);
}
void modify(int x, int pos) {
  if (Tree[x].l == Tree[x].r)
    return Tree[x].tmp = line(id[pos], id[pos]), void();
  int mid = (Tree[x].l + Tree[x].r) >> 1;
  if (pos <= mid)
    modify(x * 2, pos);
  else
    modify(x * 2 + 1, pos);
  pushup(x);
}
int query(int x) {
  if (Tree[x].l == Tree[x].r) return Tree[x].l;
  line tmp = merge(Tree[x * 2].tmp, now);
  if (tmp.x != -1) return now = tmp, query(x * 2 + 1);
  return query(x * 2);
}
int main() {
  lg[1] = 0;
  for (int i = 2; i <= 400000; i++) lg[i] = lg[i >> 1] + 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    id[a[i] = Getint()] = i;
  }
  for (int i = 2; i <= n; i++) addedge(Getint(), i);
  dfs(1, 0);
  for (int i = 1; i <= 2 * n; i++) p[i][0] = st[i];
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i + (1 << j) - 1 <= 2 * n; i++)
      if (dep[p[i][j - 1]] < dep[p[i + (1 << j - 1)][j - 1]])
        p[i][j] = p[i][j - 1];
      else
        p[i][j] = p[i + (1 << j - 1)][j - 1];
  build(1, 0, n);
  Q = Getint();
  while (Q--) {
    int op = Getint(), x, y;
    if (op == 1) {
      x = Getint();
      y = Getint();
      swap(id[a[x]], id[a[y]]);
      swap(a[x], a[y]);
      modify(1, a[x]);
      modify(1, a[y]);
    } else {
      now = line();
      cout << query(1) << "\n";
    }
  }
}

```