z-carousel
In the main amusement park in the town, a square carousel is set. It is a new type of carousel - a multi-platform carousel, where all the platforms are squares where every platform is positioned exactly in the middle of the platform below it (leaving some spaces for the seats on the side).So, the carousel looks like a pyramid. And you can see all the seats when looking from the top.
Just when little Z wanted to have some fun riding on the carousel, the automatic control of the carousel failed. Now, the manual handling must be prepared instead of the automatic one.
One line of basic platform (first line) has N chairs. Next platform line has n-2 chairs and so on. Manual handle bar has two groups of buttons: P - platform number which will rotate, (and all platform that are sitting on top of it) and R number of 90 degree degree rotation clockwise. After one manual handling ride with the carousel, seats get mixed up and visitors have problems finding their next round seats.
In next N lines there are N integers separated with blank space, which represent seats numbers on the carousel (all chairs have different number from the range 1 to N^2). The N^2 are arranged in a way you would see then if you were looking at the carousel from the sky. The numbers on the outside belong to the lowest platform,..., and the number(s) in the center belong to the highest platform.
In the next (exactly N+2nd line) there is one integer K, (1 <= K <= 100 000), number of manual commands that defined a ride.
The next K lines contain pairs of integers: Pi, (1 <= Pi <= Round(N/2)), serial number of platform to rotate (and all platform on top of it) and Ri , (0 <= Ri <= 1000), number of 90 degree degree clockwise rotation for this platform.
5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
2
1 1
2 2
Output:
13 14 15 16 1
12 19 20 21 2
11 18 25 22 3
10 17 24 23 4
9 8 7 6 5Explanation: After first command the whole carousel was rotated by 90 degrees. After second command only second and third platform are rotated for another 180 degree.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.