← Home
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, m int
		fmt.Fscan(in, &n, &m)

		col := make([]int, m)
		oddRows := 0

		for i := 0; i < n; i++ {
			var s string
			fmt.Fscan(in, &s)
			rowParity := 0
			for j := 0; j < m; j++ {
				b := int(s[j] - '0')
				rowParity ^= b
				col[j] ^= b
			}
			oddRows += rowParity
		}

		oddCols := 0
		for j := 0; j < m; j++ {
			oddCols += col[j]
		}

		if oddRows > oddCols {
			fmt.Fprintln(out, oddRows)
		} else {
			fmt.Fprintln(out, oddCols)
		}
	}
}