CF2082A.Binary Matrix

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Binary Matrix

A matrix is called binary if all its elements are either 00 or 11.

Ecrade calls a binary matrix AA good if the following two properties hold:

  • The bitwise XOR of all numbers in each row of matrix AA is equal to 00.
  • The bitwise XOR of all numbers in each column of matrix AA is equal to 00.

Ecrade has a binary matrix of size n⋅mn \cdot m. He is interested in the minimum number of elements that need to be changed for the matrix to become good.

However, it seems a little difficult, so please help him!

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤4001 \le t \le 400). The description of the test cases follows.

The first line of each test case contains two integers n,mn, m (1≤n,m≤1001 \le n, m \le 100).

This is followed by nn lines, each containing exactly mm characters consisting only of 00 and 11, describing the elements of Ecrade's matrix.

It is guaranteed that the sum of n⋅mn \cdot m across all test cases does not exceed 5⋅1045 \cdot 10^4.

Output

For each test case, output a single integer, the minimum number of elements that need to be changed.

Note

In the first test case, he needs to change 2 elements to obtain the following matrix $\begin{pmatrix}1&1&0\\1&0&1\\0&1&1\end{pmatrix}$.

In the second test case, he can make no changes to obtain the following matrix $\begin{pmatrix}0&0&0\\0&0&0\\0&0&0\end{pmatrix}$.

In the third test case, he needs to change 3 elements to obtain the following matrix $\begin{pmatrix}1&0&1\\0&0&0\\1&0&1\end{pmatrix}$.

Samples

7
3 3
010
101
010
3 3
000
000
000
3 3
100
010
001
3 3
101
010
000
3 3
000
010
000
1 4
0101
4 1
0
1
0
1
2
0
3
3
1
2
2

在线编程 IDE

建议全屏模式获得最佳体验