Bandwidth of a matrix A is defined as the smallest non-negative integer K such that A(i, j) = 0 for |i - j| > K.
For example, a matrix with all zeros will have its bandwith equal to zero. Similarly bandwith of diagonal matrix will also be zero.

For example, for the below given matrix, the bandwith of this matrix is 2.

1 0 0
0 1 1
1 1 0 

Bandwidth of the below matrix is 1. 

Bandwidth of the below matrix is 2. 

Bandwidth of the below matrix is also 2. 

You will be a given a binary matrix A of dimensions N × N. You are allowed to make following operation as many times as you wish (possibly zero or more). In a single operation, you can swap any two entries of the matrix. Your aim is to minimize the bandwidth of the matrix. Find the minimum bandwidth of the matrix A you can get after making as many operations of above type as you want.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follow.
First line of each test case contains an integer N denoting the height/width of the matrix.
Next N lines of each test case contain N space separated binary integers (either zero or one) corresponding to the entries of the matrix.

-----Output-----
For each test case, output a single integer corresponding to the minimum bandwidth that you can obtain.

-----Constraints-----
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 500
- 0 ≤ A(i, j) ≤ 1

-----Subtasks-----
- Subtask #1 (40 points) : 1 ≤ N ≤ 100
- Subtask #2 (60 points) : original constraints

-----Example-----
Input:
6
2
0 0
0 0
2
1 0
0 1
2
1 0
1 0
2
1 0
1 1
3
1 0 0
0 1 1
1 1 0
4
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1

Output:
0
0
0
1
1
3

-----Explanation-----
Example case 1. The bandwidth of a matrix will all zero entries will be zero. This is the minimum bandwidth you can get, so there is no need of performing any swap operation.
Example case 2. The bandwidth of a diagonal matrix will also be zero.
Example case 3. You can make the given matrix a diagonal matrix by swapping A(2, 1) and A(2, 2), which will have zero bandwidth.
Example case 4. You can not make swaps in any way that can reduce the bandwidth of this matrix. Bandwidth of this matrix is equal to 1, which is the minimum bandwidth that you can get.
Example case 5. Bandwidth of the given matrix is 2. You can make it equal to be 1 by swapping A(3, 1) and A(3, 3), i.e. the matrix after the operation will look like

1 0 0
0 1 1
0 1 1

The bandwidth of this matrix is 1.

Example case 6. The swap operations won't have any effect on the matrix. Its bandwidth is equal to 3.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'for _ in range(int(input())):\r\n    n = int(input())\r\n    d = {}\r\n    i = 0\r\n    while (i < n):\r\n        j = 0\r\n        o = []\r\n        o = list(map(int, input().split()))\r\n        while (j < len(o)):\r\n            x = o[j]\r\n            d[(i, j)] = x\r\n            j = j + 1\r\n\r\n        i = i + 1\r\n\r\n    do = {}\r\n    dz = {}\r\n\r\n    i = 0\r\n    while(i < n):\r\n        j = 0\r\n        while(j < n):\r\n            e = d[(i,j)]\r\n            ri = i + 1\r\n            rj = j + 1\r\n            y = abs(ri - rj)\r\n            if e == 1:\r\n                if y in do:\r\n                    do[y] = do[y]+1\r\n\r\n                else:\r\n                    do[y] = 1\r\n\r\n            else:\r\n                if y in dz:\r\n                    dz[y] = dz[y] + 1\r\n\r\n                else:\r\n                    dz[y] = 1\r\n\r\n            j = j+1\r\n\r\n        i = i+1\r\n\r\n    lo = sorted(do.keys())\r\n    lz = sorted(dz.keys())\r\n    lo = lo[::-1]\r\n    #print(lo)\r\n    #print(lz)\r\n    #print(do)\r\n    #print(dz)\r\n\r\n    i = 0\r\n    j = 0\r\n    if i == len(lo):\r\n        print(0)\r\n        continue\r\n\r\n    if j == len(lz):\r\n        print(lo[i])\r\n        continue\r\n\r\n    while((lo[i] != lz[j]) and (lo[i] > lz[j])):\r\n        ov = lo[i]\r\n        zv = lz[j]\r\n        #print(ov,zv,3)\r\n        do[ov] = do[ov]-1\r\n        dz[zv] = dz[zv]-1\r\n\r\n        if do[ov] == 0:\r\n            i = i+1\r\n            if i == len(lo):\r\n                break\r\n\r\n        if dz[zv] == 0:\r\n            j = j+1\r\n            if j == len(lz):\r\n                break\r\n\r\n    if i != len(lo):\r\n        print(lo[i])\r\n\r\n    else:\r\n        print(lz[j])'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14085