There is a matrix of size $$$n \times n$$$ which consists of 0s and 1s. The rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, the columns are numbered from $$$1$$$ to $$$n$$$ from left to right. The cell at the intersection of the $$$x$$$-th row and the $$$y$$$-th column is denoted as $$$(x, y)$$$.
AquaMoon wants to turn all elements of the matrix to 0s. In one step she can perform the following operation:
Help AquaMoon determine the minimum number of steps she need to perform to turn all elements of the matrix to 0s. We can show that an answer always exists.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). The description of the test cases follows.
The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 3000$$$).
The $$$i$$$-th of the following $$$n$$$ lines contains a binary string only of characters 0 and 1, of length $$$n$$$.
It is guaranteed that the sum of $$$n^2$$$ over all test cases does not exceed $$$9\,000\,000$$$.
For each test case, print the minimum number of steps.
35001000111011111111111111131001101106010101111101011110000000111010001110
1 2 15
In the first test case, we can use the following scheme:
Clearly, the elements of the initial matrix are not all 0, so at least one operation is required. Thus, $$$1$$$ is the answer.
In the second test case, we use the following scheme:
It can be shown that there is no way to convert all elements to 0s in $$$0$$$ or $$$1$$$ steps, so the answer is exactly $$$2$$$.
Name |
---|