#include <bits/stdc++.h>
using namespace std;
const long long N = 500 + 5, mod = 998244353;
char a[N][N];
long long sum[N][N];
long long f[N];
long long s(long long lx, long long ly, long long rx, long long ry) {
  return sum[rx][ry] - sum[lx - 1][ry] - sum[rx][ly - 1] + sum[lx - 1][ly - 1];
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long ans = 999999999;
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) {
        sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +
                     (a[i][j] == '1');
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = i + 4; j <= n; j++) {
        for (long long k = 4; k <= m; k++) {
          f[k] = s(i + 1, 1, j - 1, k - 1) - s(i, 1, i, k - 1) -
                 s(j, 1, j, k - 1) + (k - 1) * 2 +
                 (j - i - 1 - s(i + 1, k, j - 1, k));
        }
        for (long long k = m - 1; k >= 4; k--) {
          f[k] = min(f[k + 1], f[k]);
        }
        for (long long k = 1; k <= m - 3; k++) {
          long long sh = k - s(i, 1, i, k), xi = k - s(j, 1, j, k);
          ans = min(ans, f[k + 3] + (j - i - 1 - s(i + 1, k, j - 1, k)) - sh -
                             xi - s(i + 1, 1, j - 1, k));
        }
      }
    }
    cout << ans << endl;
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) sum[i][j] = 0;
    }
  }
  return 0;
}

### Prompt

Your task is to create a CPP solution to the following problem:

CQXYM found a rectangle A of size n × m. There are n rows and m columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation.

A rectangle M size of a × b is called a portal if and only if it satisfies the following conditions:

  * a ≥ 5,b ≥ 4. 
  * For all 1 < x < a, blocks M_{x,1} and M_{x,b} are obsidian blocks. 
  * For all 1 < x < b, blocks M_{1,x} and M_{a,x} are obsidian blocks. 
  * For all 1<x<a,1<y<b, block M_{x,y} is an empty block. 
  * M_{1, 1}, M_{1, b}, M_{a, 1}, M_{a, b} can be any type. 

Note that the there must be a rows and b columns, not b rows and a columns.

Note that corners can be any type

CQXYM wants to know the minimum number of operations he needs to make at least one sub-rectangle a portal.

Input

The first line contains an integer t (t ≥ 1), which is the number of test cases.

For each test case, the first line contains two integers n and m (5 ≤ n ≤ 400, 4 ≤ m ≤ 400). 

Then n lines follow, each line contains m characters 0 or 1. If the j-th character of i-th line is 0, block A_{i,j} is an empty block. Otherwise, block A_{i,j} is an obsidian block.

It is guaranteed that the sum of n over all test cases does not exceed 400.

It is guaranteed that the sum of m over all test cases does not exceed 400.

Output

Output t answers, and each answer in a line.

Examples

Input


1
5 4
1000
0000
0110
0000
0001


Output


12


Input


1
9 9
001010001
101110100
000010011
100000001
101010101
110001111
000001111
111100000
000110000


Output


5

Note

In the first test case, the final portal is like this:
    
    
      
    1110  
    1001  
    1001  
    1001  
    0111  
    

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 500 + 5, mod = 998244353;
char a[N][N];
long long sum[N][N];
long long f[N];
long long s(long long lx, long long ly, long long rx, long long ry) {
  return sum[rx][ry] - sum[lx - 1][ry] - sum[rx][ly - 1] + sum[lx - 1][ly - 1];
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long ans = 999999999;
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) {
        sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +
                     (a[i][j] == '1');
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long j = i + 4; j <= n; j++) {
        for (long long k = 4; k <= m; k++) {
          f[k] = s(i + 1, 1, j - 1, k - 1) - s(i, 1, i, k - 1) -
                 s(j, 1, j, k - 1) + (k - 1) * 2 +
                 (j - i - 1 - s(i + 1, k, j - 1, k));
        }
        for (long long k = m - 1; k >= 4; k--) {
          f[k] = min(f[k + 1], f[k]);
        }
        for (long long k = 1; k <= m - 3; k++) {
          long long sh = k - s(i, 1, i, k), xi = k - s(j, 1, j, k);
          ans = min(ans, f[k + 3] + (j - i - 1 - s(i + 1, k, j - 1, k)) - sh -
                             xi - s(i + 1, 1, j - 1, k));
        }
      }
    }
    cout << ans << endl;
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) sum[i][j] = 0;
    }
  }
  return 0;
}

```