Chef is learning linear algebra. Recently, he learnt that for a square matrix $M$, $\mathop{\rm trace}(M)$ is defined as the sum of all elements on the main diagonal of $M$ (an element lies on the main diagonal if its row index and column index are equal).
Now, Chef wants to solve some excercises related to this new quantity, so he wrote down a square matrix $A$ with size $N\times N$. A square submatrix of $A$ with size $l\times l$ is a contiguous block of $l\times l$ elements of $A$. Formally, if $B$ is a submatrix of $A$ with size $l\times l$, then there must be integers $r$ and $c$ ($1\le r, c \le N+1-l$) such that $B_{i,j} = A_{r+i-1, c+j-1}$ for each $1 \le i, j \le l$.
Help Chef find the maximum trace of a square submatrix of $A$.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$-th of these lines contains $N$ space-separated integers $A_{i,1}, A_{i,2}, \dots, A_{i, N}$ denoting the $i$-th row of the matrix $A$.

-----Output-----
For each test case, print a single line containing one integer — the maximum possible trace.

-----Constraints-----
- $1 \le T \le 100$
- $2 \le N \le 100$
- $1 \le A_{i,j} \le 100$ for each valid $i, j$

-----Subtasks-----
Subtask #1 (100 points): original constraints

-----Example Input-----
1
3
1 2 5
6 3 4
2 7 1

-----Example Output-----
13

-----Explanation-----
Example case 1: The submatrix with the largest trace is 
6 3
2 7

which has trace equal to $6 + 7 = 13$. (This submatrix is obtained for $r=2, c=1, l=2$.)

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
T=int(input())
for k in range(0,T):
 N=int(input())
 matrix=[]
 for i in range(0,N):
  a=list(map(int, input().split()))
  matrix.append(a)
 max_trace = []
 for i in range(0,N):
  trace1=0
  trace2=0
  for j in range(0,i+1):
   trace1+=matrix[j][N+j-i-1]
   trace2+=matrix[N+j-i-1][j]
   max_trace.append(trace1)
   max_trace.append(trace2)
 print(max(max_trace))

 


t = int(input())

for _ in range(t):
 n = int(input())
 
 a = []
 for i in range(n):
  temp = [int(x) for x in input().split()]
  a.append(temp)
 
  # print(a)
 
 trace = 0
 
 i = 0
 for j in range(n):
  r = i
  c = j
  
  m = a[r][c]
  
  while(r<n-1 and c<n-1):
   r += 1
   c += 1
   
   m += a[r][c]
  
  # print(m)
  if(m > trace):
   trace = m
 
 i = 0
 for j in range(1, n):
  r = j
  c = i
  
  m = a[r][c]
  
  while(r<n-1 and c<n-1):
   r += 1
   c += 1
   
   m += a[r][c]
  
  # print(m)
  
  if(m > trace):
   trace = m
 
 print(trace)

# cook your dish here
for i in range(int(input())):
 h = int(input())
 f = []
 ans = []
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  sum1 = 0
  sum2 = 0
  for l in range(0,k+1):
   sum1 += f[l][h+l-k-1]
   sum2 += f[h+l-k-1][l]
   
  ans.append(sum1)
  
  ans.append(sum2)
  
 print(max(ans))


for i in range(int(input())):
 h = int(input())
 f = []
 ans = []
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  sum1 = 0
  sum2 = 0
  for l in range(0,k+1):
   sum1 += f[l][h+l-k-1]
   sum2 += f[h+l-k-1][l]
   
  ans.append(sum1)
  
  ans.append(sum2)
  
 print(max(ans))


t = int(input())
for i in range(t):
 n = int(input())
 matrix = []
 for j in range(n):
  a = list(map(int, input().split(' ')))
  matrix.append(a)
 final_sum = 0 
 for k in range(n):
  sum1 = 0
  sum2 = 0
  for p in range(0,k+1):
   sum1 += matrix[p][n+p-k-1]
   sum2 +=matrix[n+p-k-1][p]
  sumo = max(sum1,sum2)
  final_sum = max(sumo,final_sum)
 print(final_sum) 

# cook your dish here
for i in range(int(input())):
 h = int(input())
 f = []
 ans = []
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  sum1 = 0
  sum2 = 0
  for l in range(0,k+1):
   sum1 += f[l][h+l-k-1]
   # print(sum1)
   sum2 += f[h+l-k-1][l]
   # print(sum2)
  ans.append(sum1)
  # print(ans)
  ans.append(sum2)
  # print(ans)
 print(max(ans))

for i in range(int(input())):
 h = int(input())
 f = []
 su = []
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  s = 0
  s1 = 0
  for l in range(0,k+1):
   s += f[l][h+l-k-1]
   s1 += f[h+l-k-1][l]
  su.append(s)
  su.append(s1)
 print(max(su))

# cook your dish here
for i in range(int(input())):
 h = int(input())
 f = []
 su = []
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  s = 0
  s1 = 0
  for l in range(0,k+1):
   s += f[l][h+l-k-1]
   s1 += f[h+l-k-1][l]
  su.append(s)
  su.append(s1)
 print(max(su))

# cook your dish here
t = int(input())
while(t):
  t-=1
  n, = list(map(int,input().split()))
  arr =[]
  for i in range(n):
   arr.append([int(x) for x in input().split()])
  for i in range(n-1):
   for j in range(n-1):
    arr[i+1][j+1]+=arr[i][j]
  ans = -float('inf')
  for i in range(n):
   for j in range(n):
    ans=max(ans,arr[i][j])
  print(ans)


t = int(input())
while(t):
  t-=1
  n, = list(map(int,input().split()))
  arr =[]
  for i in range(n):
   arr.append([int(x) for x in input().split()])
  for i in range(n-1):
   for j in range(n-1):
    arr[i+1][j+1]+=arr[i][j]
  ans = -float('inf')
  for i in range(n):
   for j in range(n):
    ans=max(ans,arr[i][j])
  print(ans)


# cook your dish here
for i in range(int(input())):
 h = int(input())
 f = []
 su = []
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  s = 0
  s1 = 0
  for l in range(0,k+1):
   s += f[l][h+l-k-1]
   s1 += f[h+l-k-1][l]
  su.append(s)
  su.append(s1)
 print(max(su))

def trace_of_matrix_v2(matrix):
 _list = []
 for diff in range(len(matrix)):
  sum1, sum2, index = (0, 0, diff)
  for i in range(len(matrix) - diff):
   sum1 += matrix[index][i]
   sum2 += matrix[i][index]
   index += 1
  _list.append(sum1)
  _list.append(sum2)
 return max(_list)


def __starting_point():
 t = int(input())
 for _ in range(t):
  n = int(input())
  _list = []
  for _ in range(n):
   _list.append(list(map(int, input().split())))
  print(trace_of_matrix_v2(_list))
__starting_point()

# cook your dish here
tests = int(input())

for test in range(tests):
 N = int(input())

 a = []
 for row in range(N):
  a.append([int(x) for x in input().split()])
 
 max_a = []
 for i in range(N):
  max_c = 0
  count = i
  for j in range(N-i):
   if count < N:
    max_c += a[j][count]
   count += 1

  max_a.append(max_c)

 for i in range(N):
  if i == 0: continue

  max_c = 0
  count = i
  for j in range(N-i):
   if count < N:
    max_c += a[count][j]
   count += 1
  max_a.append(max_c)
  
 print(max(max_a))

import numpy as np
'''
def findTrace(i,j,k):
    trace = 0
    for z in range(0,k+1):
     trace+=matrix[i+z][j+z]
    return trace
'''

def traceSum(matrix,n):
 sum,round,j = 0,n-1,0
 i = round
 sumArray = []
 
 while (i>=0):
  while(i<n):
   sum+=matrix[i][j]
   i+=1
   j+=1
   
  round-=1
  i,j = round,0
  sumArray.append(sum)
  sum = 0
  
 round = n-1
 i,j = 0,round
 
 while (j>0):
  while(j<n):
   sum += matrix[i][j]
   i+=1
   j+=1
  
  round-=1
  i,j = 0,round
  sumArray.append(sum)
  sum = 0
 return max(sumArray)


 
t = int(input())
for i in range(t):
 #Array Size is n
 n = int(input())
 a=[]
 
 for i in range(0,n):
  ele = list(map(int,input().split()))
  a.append(ele)
  
 matrix = np.array(a).reshape(n,n)
 
 #print(matrix)
 '''
    This worked but had a n^3 complexity and gave an error of time limit         exceeded on submission.
    trace = 0
    for i in range(0,n):   #Row number
     for j in  range(0,n):   #Column number
      for k in range(0,n):   #Length of Sub-matrix
       if i+k<n and j+k<n:
        trace = max(trace,findTrace(i,j,k))  #Check trace of every                         sub-matrix & get max
        '''
 print(traceSum(matrix,n))
 


# cook your dish here
a=int(input())
for i in range(0,a):
 h=int(input())
 f=[]
 su=[]
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  s=0
  s1=0
  for l in range(0,k+1):
   s=s+f[l][h+l-k-1]
   s1=s1+f[h+l-k-1][l]
  su.append(s)
  su.append(s1)
 print(max(su))

# cook your dish here
a=int(input())
for i in range(0,a):
 h=int(input())
 f=[]
 su=[]
 for j in range(0,h):
  f.append(list(map(int,input().split())))
 for k in range(0,h):
  s=0
  s1=0
  for l in range(0,k+1):
   s=s+f[l][h+l-k-1]
   s1=s1+f[h+l-k-1][l]
  su.append(s)
  su.append(s1)
 print(max(su))

for t in range(int(input())):
 l = int(input())
 m = []
 for r in range(l):
  m.append(list(map(int,input().split())))
 maxsum = 0
 for i in range(l):
  s1 = 0
  s2 = 0
  for j in range(i+1):
   s1 += m[j][l+j-i-1]
   s2 += m[l+j-i-1][j]
  if maxsum<s1:
   maxsum=s1
  if maxsum<s2:
   maxsum=s2
 
   
 print(maxsum)

# cook your dish here
t=int(input())
for i in range(t):
 n=int(input())
 mat=[]
 for i in range(n):
  l=list(map(int,input().split()))
  mat.append(l)
 ans=[]
 for x in range(n-1,-1,-1):
  s=0
  for i,j in zip(range(n),range(x,n)):
   s+=mat[i][j]
  ans.append(s)
 for y in range(1,n):
  s1=0
  for i,j in zip(range(y,n),range(n)):
   s1+=mat[i][j]
  ans.append(s1)
 print(max(ans))

t=int(input())
for i in range(t):
 n=int(input())
 mat=[]
 for i in range(n):
  l=list(map(int,input().split()))
  mat.append(l)
 ans=[]
 for x in range(n-1,-1,-1):
  s=0
  for i,j in zip(list(range(n)),list(range(x,n))):
   s+=mat[i][j]
  ans.append(s)
 for y in range(1,n):
  s1=0
  for i,j in zip(list(range(y,n)),list(range(n))):
   s1+=mat[i][j]
  ans.append(s1)
 print(max(ans))


for _ in range(int(input())):
 n=int(input())
 m=[]
 for i in range(n):
  m.append(list(map(int,input().split())))
 lo=[0 for i in range(n)]
 up=[0 for i in range(n)]
 t=0
 for i in range(n):
  for j in range(n):
   if i>j:
    lo[i-j]=lo[i-j]+m[i][j]
   elif i<j:
    up[j-i]=up[j-i]+m[i][j]
   else:
    t=t+m[i][j]
 print(max(lo+up+[t]))