You have found a strange device that shows a
The grid is partitioned into an
You notice that the device can perform
- Type
1
: In every row, swap the numbers on each of the adjacent pairs of cells with the same colour. - Type
2
: In every row, swap the numbers on each of the adjacent pairs of cells with different colours. - Type
3
: In every column, swap the numbers on each of the adjacent pairs of cells with the same colour. - Type
4
: In every column, swap the numbers on each of the adjacent pairs of cells with different colours. - Type
5
: Rotate every white subgrid clockwise and rotate every black subgrid counterclockwise.
Now you wonder: What is the final state of the grid after performing
Constraints
Subtask 1 [10%]
There are only type 1
, 3
, and 5
operations.
Subtask 2 [25%]
There are only type 1
and 2
operations.
Subtask 3 [10%]
There are only type 1
, 2
, 3
, and 4
operations.
Subtask 4 [55%]
No additional constraints.
Input Specification
The first line contains
The next
Output Specification
Output
Sample Input
2 3 5
3
1
4
2
5
Sample Output
20 8 12 24 21 9
22 10 7 19 23 11
4 16 13 1 5 17
2 14 18 6 3 15
Explanation
After the first operation, the grid looks like:
After the second operation, the grid looks like:
After the third operation, the grid looks like:
After the fourth operation, the grid looks like:
After the fifth operation, the grid looks like:
Comments