| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 1024 MB | 6 | 1 | 1 | 100.000% |
There is an $n$ by $m$ grid of black and white squares. In one operation, you can pick any two adjacent squares of the same color and swap the colors of both. For example, here is a valid sequence of two operations on a grid with $n=4,ドル $m=3$:
You are also given a target grid of $n$ by $m$ black and white squares. Perform at most 200ドルnm$ operations on the starting grid to reach the target grid, or state that it is impossible to do so. You do not need to minimize the number of operations.
It can be shown that if there is a solution, there is one that uses at most 200ドルnm$ operations.
The first line of the input contains a single integer $t$ (1ドル \le t \le 500$) --- the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $n$ and $m$ (1ドル \le n, m \le 50$) --- the number of rows and columns in the grid, respectively.
The $i$-th of the next $n$ lines contains $m$ characters describing the $i$-th row of the starting grid. The $j$-th of these is '\#' if the square at position $(i, j)$ is black, and '.' if the square at position $(i, j)$ is white.
The next $n$ lines describe the target grid in the same format as the starting grid.
It is guaranteed that the sum of $n\cdot m$ over all test cases does not exceed 2500ドル$.
For each test case, if there is no solution, output a single integer $-1$.
Otherwise, the first line of output for each test case should contain a single integer $k$ (0ドル \le k \le 200nm$) --- the number of operations you will perform.
The next $k$ lines of output should each contain four integers $i_1,ドル $j_1,ドル $i_2,ドル and $j_2$ (1ドル \le i_1, i_2 \le n,ドル 1ドル \le j_1, j_2 \le m$) --- the two adjacent squares $(i_1, j_1)$ and $(i_2, j_2)$ that are part of this operation.
If there are multiple solutions, print any.
6 3 3 ..# .#. .#. #.# ..# .## 4 6 #.#.#. .#.#.# #.#.#. .#.#.# ...... ...... ...... ...... 1 1 # # 4 5 #...# ...#. ###.# ....# ..#.# .#... ###.# .##.# 1 8 ...#.... ........ 4 2 .. .. .. .. ## ## ## ##
3 1 1 1 2 1 2 2 2 2 3 3 3 -1 0 5 1 2 1 3 2 2 2 3 1 1 1 2 2 3 2 4 4 2 4 3 -1 4 1 1 1 2 4 1 4 2 2 1 3 1 2 2 3 2
Here is the sequence of 3ドル$ operations described by the output of the first test case:
It is impossible to perform any operations in the second test case, so it is not possible to reach the target grid.