You are given a matrix of size r \times c. Each element of the matrix can be either or . In each operation, you can flip any element of this matrix, i.e., change a to or a to . Your goal is to transform the matrix such that:
Each row contains the same number of 's,
Each column contains the same number of 's.
What is the minimum number of operations required to achieve this?
The input starts with a positive integer (), the number of test cases.
Each test case begins with two integers and (1 \leq r, c \leq 40), the number of rows and columns of the matrix, respectively. Each of the following lines contains integers, either or , which represent the matrix elements.
For each test case, output a single line in the format "Case #: R", where # is the test case number (starting from ), and is the minimum number of operations needed to reach the target matrix. If it is not possible to obtain such a matrix, replace with .
Esempio 1