Painting
There is a wall made up of n×n tiles. These tiles were originally painted in k different colors. Over time, the paint has faded, and now the wall needs to be repainted. This time, all tiles must be painted in just one of the k colors. In one move, you can paint an entire horizontal or vertical row of tiles. However, you can only paint a row in a particular color if at least two tiles in that row (either horizontal or vertical) are already painted in that color (whether it's the old paint or new). Your task is to find the minimum number of moves needed to repaint all the tiles.
Input
The first line of the input contains the number of test cases. For each test case, the first line contains two integers: n (1 < n < 500) - the number of tiles in each row, and k (1 ≤ k < n) - the number of different colors. Each of the next n lines contains n integers, representing the color numbers of the tiles. Colors are numbered from 1 to k.
Output
For each test case, the first line of the output should contain the number q - the minimum number of moves required to paint all the tiles. On the second line, list all the colors in which the wall can be painted using the minimum number of moves, in ascending order. If it is impossible to paint the wall according to the given rules, output only the number 0.