Combination Lock
시간 제한1초메모리 제한1024 MB
3-다이얼과 5-다이얼이 체커판처럼 놓인 격자에서 목표 값을 만족하도록, 한 번의 이동이 칸과 상하좌우 이웃을 증가시킬 때 20nm 이하의 이동 순서를 찾는다.
문제
You are faced with a combination lock that consists of an by grid of dials. A -dial is a dial that can display values . A -dial currently displaying value can be incremented to make it display value .
This particular lock consists of -dials and -dials in a checkerboard arrangement, with the top left dial being a -dial. In a single move, you can increment a dial and all of its horizontal and vertical neighbors.
For example, here is one possible sequence of moves on a grid with , (where -dials are gray and -dials are white):

Initially, all of the dials are displaying . You remember what positions the dials must be in for the lock to open, but you forgot the combination of moves to reach it. Find a sequence of moves that sets all dials to the correct positions. You do not need to minimize the number of moves, but you can use no more than moves.
It can be shown that such a solution always exists.
입력
The first line of the input contains a single integer () --- the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers and () --- the number of rows and columns in the grid, respectively.
The -th of the next lines contains integers describing the -th row of the combination. The -th of these is , the desired position of the dial at position . If is even, . Otherwise, .
It is guaranteed that the sum of over all test cases does not exceed .
출력
The first line of output for each test case should contain a single integer () --- the number of moves you will perform.
The next lines of output should each contain integers and , indicating that the next move will be performed at position .
If there are multiple solutions, print any.
힌트
Here is the move used in the first sample case:

In the second sample case, the lock is already in the target position, so no moves are needed.