Nikhil got to know about what is a matrice. He made several patterns using 1-d and 2-d matrices. One of which was his favorite pattern. Your task is to right a code for his favorite pattern.

NOTE :- To understand his favorite pattern see the sample output

Input:-

First line of code takes number of test cases 'N' as its input. The following N lines take size 'S' of a sqaure matrice as its input.

Output:-

Print Nikhils favorite pattern and seperate two different test cases with an empty line.

Constraint:-

N ≤ 10

S ≤ 10

SAMPLE INPUT
1
3

SAMPLE OUTPUT
123
894
765
def spiral(n):
    dx,dy = 1,0            # Starting increments
    x,y = 0,0              # Starting location
    myarray = [[None]* n for j in range(n)]
    for i in xrange(n**2):
        myarray[x][y] = i
        nx,ny = x+dx, y+dy
        if 0<=nx<n and 0<=ny<n and myarray[nx][ny] == None:
            x,y = nx,ny
        else:
            dx,dy = -dy,dx
            x,y = x+dx, y+dy
    return myarray
 
def printspiral(myarray):
    n = range(len(myarray))
    for y in n:
        s=""
        for x in n:
            s+=str(myarray[x][y]+1)
        print s
 
t=input()
while t:
    t-=1
    printspiral(spiral(input()))
    print