Soup has infiltrated Lakshy's top secret lab! Inside this lab are the secrets on how to survive the IB program. However, to get in Soup would need to bypass a sophisticated security lock. The security lock is an by
matrix of cells. Soup has gained intel that the value of cell
(that is, the
row and
column) would be
by default. To pass the lock, Soup will need to answer
queries, the
asking for the value of a particular cell
. Unfortunately, Soup was also informed that the numbers on the grid have been scrambled in
successive rotation operations! In the
operation, Lakshy rotates the square with top left corner
and bottom right corner
by 90 degrees clockwise. Overwhelmed by the difficulty, Soup cannot unlock the security lock, so he has come to you, his trusty accomplice, to help him!
Constraints
For all subtasks:
Subtask 1 [20%]
Subtask 2 [80%]
No additional constraints.
Input Specification
The first line contains three integers, .
The next lines each contain four integers,
.
The next lines each contain two integers,
.
Output Specification
For each of the queries, output on a separate line the value of cell
.
Sample Input
3 2 2
1 1 3 3
2 2 3 3
3 2
1 2
Sample Output
3
4
Explanation
Before any rotations, the matrix looks like this:
1 2 3
4 5 6
7 8 9
After the first rotation, the matrix looks like this:
7 4 1
8 5 2
9 6 3
After the second rotation, the matrix looks like this:
7 4 1
8 6 5
9 3 2
Thus the cell at is
and the cell at
is
.
Comments