#P1720C. Corners
Corners
Description
You are given a matrix consisting of rows and columns. Each cell of this matrix contains or .
Let's call a square of size without one corner cell an L-shape figure. In one operation you can take one L-shape figure, with at least one cell containing and replace all numbers in it with zeroes.
Find the maximum number of operations that you can do with the given matrix.
The first line contains one integer () — the number of test cases. Then follow the descriptions of each test case.
The first line of each test case contains two integers and () — the size of the matrix.
Each of the following lines contains a binary string of length — the description of the matrix.
It is guaranteed that the sum of and the sum of over all test cases does not exceed .
For each test case output the maximum number of operations you can do with the given matrix.
Input
The first line contains one integer () — the number of test cases. Then follow the descriptions of each test case.
The first line of each test case contains two integers and () — the size of the matrix.
Each of the following lines contains a binary string of length — the description of the matrix.
It is guaranteed that the sum of and the sum of over all test cases does not exceed .
Output
For each test case output the maximum number of operations you can do with the given matrix.
Note
In the first testcase one of the optimal sequences of operations is the following (bold font shows l-shape figure on which operation was performed):
- Matrix before any operation was performed:
1 0 1 1 1 1 0 1 1 1 1 0 - Matrix after operation was performed:
1 0 0 1 0 1 0 1 1 1 1 0 - Matrix after operations were performed:
1 0 0 1 0 0 0 1 1 1 1 0 - Matrix after operations were performed:
1 0 0 1 0 0 0 1 0 1 1 0 - Matrix after operations were performed:
1 0 0 0 0 0 0 1 0 1 1 0 - Matrix after operations were performed:
1 0 0 0 0 0 0 1 0 1 0 0 - Matrix after operations were performed:
1 0 0 0 0 0 0 0 0 1 0 0 - Matrix after operations were performed:
0 0 0 0 0 0 0 0 0 1 0 0 - Matrix after operations were performed:
0 0 0 0 0 0 0 0 0 0 0 0
In the third testcase from the sample we can not perform any operation because the matrix doesn't contain any ones.
In the fourth testcase it does not matter which L-shape figure we pick in our first operation. We will always be left with single one. So we will perform operations.