T = int(input())
def tornado(n):
if n == 1:
return [[1]]
x = 0; y=0;d=0
answer = [[0 for i in range(n)] for j in range(n)]
for i in range(n*n):
answer[x][y] = i+1
if d == 0:
y += 1
if y == n-1 or answer[x][y+1]!=0:
d = 1
elif d == 1:
x+=1
if x == n-1 or answer[x+1][y]!=0:
d=2
elif d == 2:
y -= 1
if y == 0 or answer[x][y-1]!=0:
d=3
elif d==3:
x-=1
if x == n-1 or answer[x-1][y] != 0:
d=0
return answer
for test_case in range(1, T + 1):
print(f"#{test_case}")
n = int(input())
s = tornado(n)
for i in range(n):
ss = list(map(str,s[i]))
a = ' '.join(ss)
print(a)
T = int(input())
def sol(n):
answer = [[1]*(i+1) for i in range(n)]
for i in range(2,n):
l = answer[i]
for k in range(1,len(l)-1):
answer[i][k] = answer[i-1][k-1]+answer[i-1][k]
return answer
for test_case in range(1, T + 1):
n = int(input())
answer = sol(n)
print(f"#{test_case}")
for i in range(n):
a = list(map(str,answer[i]))
a = ' '.join(a)
print(a)
T = int(input())
def sol(n,m):
nn = []
for i in range(n):
inputt = list(map(int,input().split()))
p = []
for k in range(n-m+1):
p.append(sum(inputt[k:k+m]))
nn.append(p)
answer = 0
answer = 0 ; aa = []
for i in range(len(nn[0])): #열 5-2+1 [0,1,2,3]
p = 0
while p != n-m+1:
a = 0
for j in range(p,p+m): #행 [0,2]
a += nn[j][i]
aa.append(a)
if answer < a:
answer = a
p+=1
return answer
for test_case in range(1, T + 1):
n,m = map(int,input().split())
print(f"#{test_case} {sol(n,m)}")