Loops
시간 제한2초메모리 제한1024 MB
n 곱하기 m 격자의 모든 2x2 정사각형에 대한 루프 모양이 주어질 때, 그 모양을 만드는 1부터 nm까지의 서로 다른 정수 행렬을 복원한다.
문제
Consider four integers , , , and , such that . Let's put them in the corners of a square in some order and draw a loop . Depending on the arrangement of the integers, we can get different loop shapes, but some arrangements produce the same shape:

There are three possible loop shapes we can get:

Now consider an matrix filled with distinct integers from to , inclusive. Each square in this matrix can be seen as a square with integers in its corners. Let's build a loop for each of these squares like we did before:

Your task is to perform the inverse operation. You are given the shape types for all loops, and you need to build an matrix filled with distinct integers from to , inclusive, that produces these shapes.
입력
The first line contains two integers and ().
Each of the next lines contains a string of characters without spaces. Each character is a digit from to , denoting the type of the shape of the corresponding loop.
출력
Print an matrix filled with distinct integers from to , inclusive, that produces the shapes of the loops in the input.
It can be shown that such a matrix always exists. If there are multiple answers, print any of them.