Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.

A permutation is an array consisting of $N$ distinct integers from $1$ to $N$ in arbitrary order.

Chef has two permutation arrays $A$ and $P$ of length $N$. Chef performs the following three types of operations on the array $A$:
$1$ : Permute the array $A$ according to the order defined by permutation $P$.That is, replace $A$ with the array $B$ where $B[P[i]]=A[i]$.
$2 \ x \ y$ : Swap the elements at positions $x$ and $y$ in $A$.
$3 \ x$ : Output the element at position $x$ in array $A$. 

For each operation of type $3$, Chef wants you to output the element at position $x$ in array $A$ after all preceding operations have been applied.

------ Input ------

The first line contains an integer $T$, the number of test cases. Then the test cases follow. 
The first line of each test case contains a single integer $N$.
The second line contains $N$ integers denoting elements of array $A$.
The third line contains $N$ integers denoting elements of array $P$.
The fourth line contains a single integer $Q$, denoting the number of operations to be performed.
$Q$ lines follow, each describing an operation of one of the three types above.

------ Output ------
For each test case, for each query of type $3$, output the answer in a separate line.

------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ N, Q ≤ 10^{5}$
$1 ≤ A[i],P[i], x, y ≤ N$
$A$ and $P$ are permutations.
$x\ne y$ in type $2$ operations.
The sum of $N$ and the sum of $Q$ over all test cases do not exceed $10^{5}$.

----- Sample Input 1 ------ 
1

3

1 2 3

2 3 1

3

1

2 2 3

3 1
----- Sample Output 1 ------ 
3
----- explanation 1 ------ 
Initially, array $A$ is $[1,2,3]$.
It changes as follows: $[1,2,3]$ -> $[3,1,2]$ -> $[3,2,1]$.
So, we output element at position $1$ in array $A$, which is $3$.