There is a row with N blocks. Blocks are numbered from left to right in 1-based indexing. The value of the i-th block is ai.
You are on the 1-th blocks now. For convenience, let's call the block you currently on as happy block. Of course you can only be on one block at the same time.
Now you need to execute Q operations. There are three kinds of operations:
It's guaranteed that:
Note: be careful of the efficiency of your strategy.
The first line contains one integer N (1 ≤ N ≤ 5 x 105) – the number of blocks.
The second line contains N integers a1, a2, ..., aN (0 ≤ ai ≤ 109) – the value of each block.
The third line contains one integer Q (1 ≤ Q ≤ 5 x 105) – the number of operations you need to execute.
Then Q lines follow. The i+3-th line contains one integer typei (1 ≤ typei ≤ 3) – the type of operations you need to execute. If typei = 1 then one integer dir (dir = -1 or dir = 1) follows – -1 for moving to the block which is on the left to happy block and 1 for the right.
It's guaranteed that:
For every 2nd type operations, output the value of happy block then.