Codeforces Round 1010 (Div. 2, Unrated)
A
Binary Matrix
Codeforces
800
原题
←B →
翻译中…

A matrix is called binary if all its elements are either $0$ or $1$.

翻译中…

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

翻译中…
  • The bitwise XOR of all numbers in each row of matrix $A$ is equal to $0$.
  • The bitwise XOR of all numbers in each column of matrix $A$ is equal to $0$.
翻译中…

Ecrade has a binary matrix of size $n \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 $t$ ($1 \le t \le 400$). The description of the test cases follows.

翻译中…

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

翻译中…

This is followed by $n$ lines, each containing exactly $m$ characters consisting only of $0$ and $1$, describing the elements of Ecrade's matrix.

翻译中…

It is guaranteed that the sum of $n \cdot m$ across all test cases does not exceed $5 \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}$.

翻译中…

样例

Input #1
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
Output #1
2
0
3
3
1
2
2
InputCopy OutputCopy
题目信息
题号
2082A
时间限制
1 s
内存限制
512 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。