public class App {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int cases = Integer.parseInt(sc.nextLine());
for (int i = 0; i < cases; ++i) {
int m = sc.nextInt();
int n = sc.nextInt();
sc.nextLine();
int[][] matrix = new int[m][n];
int[] rowCnt = new int[m];
int[] colCnt = new int[n];
int oddCnt1 = 0, oddCnt2 = 0;
for (int j = 0; j < m; ++j) {
String s = sc.nextLine();
for (int k = 0; k < n; ++k) {
matrix[j][k] = s.charAt(k) - '0';
rowCnt[j] += matrix[j][k];
colCnt[k] += matrix[j][k];
}
}
for (int j = 0; j < m; ++j) oddCnt1 += rowCnt[j] % 2;
for (int j = 0; j < n; ++j) oddCnt2 += colCnt[j] % 2;
System.out.println("output: " + Math.max(oddCnt1, oddCnt2));
}
sc.close();
}
}