children are playing a game of Rotate and Speak. In this game all the children are given a number plate which contains distinct values and they need to form a circle in clockwise order.
There are turns in this game. In each turn two numbers and are announced. The rules of the game are as follows :
Input format:
First line contains an intege that denotes the number of test cases
First line in every test case contains an integer denoting the count of children playing the game.
Second line in every test case contains space separated integers , here the integer is the number on the number plate of the student
Third line in every test case contains an integer ,number of turns in the game.
Following lines ,each contain two integers describing one of the types of moves in a turn.
Output format:
For each moves of type 3, you have to print the number that will be spoken in that turn of the game.
Constraints:
Note- Since input files are large, use fast input/output methods.
task 1: number plate of 2nd child = 3.
task 2: rotate the circle 1 step anticlockwise, the arrangement becomes {1,3,2}.
task 3: number plate of 2nd child = 2.
taks 4: rotate the circle 2 steps towards right , the arrangement becomes {3,2,1}.
task 5: number plate of 2nd child = 1.