Mirko has just installed a brand new drawing program. The program supports different colours, denoted by integers from to . All drawing is performed on a canvas with dimensions . In the beginning, all cells are white (denoted by ).
The upper left cell of the canvas has coordinates . The first coordinate, , increases iterating over rows, and the second, , increases iterating over columns.
Mirko's favourite pastime is drawing rectangular checkerboard patterns using the command PAINT c x1 y1 x2 y2
, where denotes the chosen colour, and and are coordinates of the upper left and lower right cells, respectively, of the rectangle being painted.
The upper left cell of the rectangle will be painted in the chosen colour, while the rest are determined by the checkerboard pattern. Cells that are not painted over by the chosen colour will retain their previous colour. For example, a white canvas painted over by a red checkerboard pattern will look like this:
Mirko has recently discovered two additional commands. He can save his painting at any time using the creatively named command SAVE
, and load it again later using the command LOAD x
, where is a positive integer representing the ordinal number of the save.
Unfortunately, the program has crashed and Mirko's painting is lost forever. Luckily, Mirko has saved a log of all used commands. Can you help Mirko by reconstructing the lost painting?
Input Specification
The first line of input contains three positive integers, , , and (, is the number of commands).
Each of the following lines contains one of the three described commands. Input will not contain any illegal commands.
Output Specification
Output must consist of lines, each containing integers representing the colours of cells in the corresponding row of the painting.
Sample Input 1
4 3 2
PAINT 2 0 0 3 3
PAINT 3 0 3 3 3
Sample Output 1
2 1 2 3
1 2 1 2
2 1 2 3
1 2 1 2
Sample Input 2
3 3 4
PAINT 3 0 0 1 1
SAVE
PAINT 2 1 1 2 2
LOAD 1
Sample Output 2
3 1 1
1 3 1
1 1 1
Sample Input 3
3 4 7
PAINT 2 0 0 1 1
SAVE
PAINT 3 1 1 2 2
SAVE
PAINT 4 0 2 0 2
LOAD 2
PAINT 4 2 0 2 0
Sample Output 3
2 1 1
1 3 1
4 1 3
Comments