Grievous Lady
시간 제한1초메모리 제한1024 MB
인접한 칸끼리 다른 색이 되도록 N×M 격자를 4가지 색으로 칠하되, 테두리에 미리 칠해진 칸을 지키고 아무 완성본이나 출력한다.
문제
You are given a grid of size . Your task is to color each cell of the grid with one of four colors: , , , or .
There is only one rule: any two adjacent cells must have different colors. Two cells are considered adjacent if they share a common edge.
Some cells in the grid may already be colored. These pre-colored cells are located only on the border of the grid. You must color all the remaining empty cells to create a complete grid that satisfies the rule.
입력
The first line of the input contains a single integer , the number of test cases.
The first line of each test case contains two integers and .
The next lines describe the initial state of the grid. Each line contains space-separated integers. A value of represents an empty cell, while values from to represent a cell colored with that specific color.
출력
For each test case, output lines representing the completed grid.
Each line should contain space-separated integers, where each integer is a color from to .
If multiple solutions exist, you may print any one of them.
제한
- The sum of over all test cases does not exceed .
- In the initial grid, any non-zero cells are located only on the border (the first or last row, or the first or last column)
- It is guaranteed that a solution always exists for the given input.