Score : $300$ points
We have $HW$ cards arranged in a matrix with $H$ rows and $W$ columns.
For each $i=1, \ldots, N$, the card at the $A_i$-th row from the top and $B_i$-th column from the left has a number $i$ written on it. The other $HW-N$ cards have nothing written on them.
We will repeat the following two kinds of operations on these cards as long as we can.
Find the position of each numbered card after the end of the process above. It can be proved that these positions are uniquely determined without depending on the order in which the operations are done.
Input is given from Standard Input in the following format:
$H$ $W$ $N$ $A_1$ $B_1$ $\vdots$ $A_N$ $B_N$
Print $N$ lines.
If, after the end of the process, the card with the number $i$ is at the $C_i$-th row from the top and $D_i$-th column from the left, the $i$-th line should contain $C_i$ and $D_i$ in this order with a space between them.
4 5 2 3 2 2 5
2 1 1 2
Let *
represent a card with nothing written on it. The initial arrangement of cards is:
***** ****2 *1*** *****
After the end of the process, they will be arranged as follows:
*2 1*
Here, the card with $1$ is at the $2$-nd row from the top and $1$-st column from the left, and the card with $2$ is at the $1$-st row from the top and $2$-nd column from the left.
1000000000 1000000000 10 1 1 10 10 100 100 1000 1000 10000 10000 100000 100000 1000000 1000000 10000000 10000000 100000000 100000000 1000000000 1000000000
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10