There is a wall made of $n \times n$ tiles. Long ago each tile was painted in one of $k$ colors. The paint has worn out, so the wall must be repainted, and this time every tile must end up in a single one of the $k$ colors.
In one move you may repaint one whole horizontal row or one whole vertical column of tiles into a color of your choice. However, you may paint a row or a column into color $c$ only if at least two of its tiles are already color $c$ (either from the original painting or from an earlier move).
Every tile must be repainted (covered by at least one move), and in the end all tiles must share the same color. Determine the minimum number of moves needed, and for which target colors that minimum is achieved.
The first line contains the number of test cases. For each test case, the first line contains two integers $n$ and $k$ with $1 < n \le 500$ (the number of tiles in a row) and $1 \le k < n$ (the number of available colors). Each of the next $n$ lines contains $n$ integers between $1$ and $k$, giving the original color of every tile.
For each test case, print two lines. The first line contains $q$, the minimum number of moves needed to repaint the whole wall into a single color. The second line lists, in increasing order and separated by single spaces, all colors into which the wall can be repainted in exactly $q$ moves. If it is impossible to repaint the wall under the rules for any color, print a single line containing just $0$.