The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow. 
- Each test case contains a single line of input, one integer $K$. 
-----Output:-----
For each test case, output as the pattern.
-----Constraints-----
- $1 \leq T \leq 50$
- $1 \leq K \leq 50$
-----Sample Input:-----
5
1
2
3
4
5
-----Sample Output:-----
1
1
23
1
23
456
1
23
4 5
6789
1
23
4 5
6  7
89101112
-----EXPLANATION:-----
No need, else pattern can be decode easily.
# cook your dish here
# cook your dish here
def solve():
    n = int(input())
    #n,m = input().split()
    #n = int(n)
    #m = int(m)
    #s = input()
    #a = list(map(int, input().split()))
    it = 1
    k=1
    for i in range(n):
        j=0
        while j<it:
            mark=1
            if (i==n-1 or (j==0 or j==it-1) ): 
                print(k,end="")
                k+=1
            else:
                print(" ",end="")
               # continue
            j+=1
        print("")
        it+=1
        
            
    
    
def __starting_point():
    T = int(input())
    for i in range(T):
        #a = solve()
        #n = len(a)
        #for i in range(n):
         #   if i==n-1 : print(a[i])
          #  else: print(a[i],end=" ")
        (solve())
__starting_point()
# cook your dish here
# cook your dish here
def solve():
    n = int(input())
    #n,m = input().split()
    #n = int(n)
    #m = int(m)
    #s = input()
    #a = list(map(int, input().split()))
    it = 1
    k=1
    for i in range(n):
        j=0
        while j<it:
            mark=1
            if (i==n-1 or (j==0 or j==it-1) ): 
                print(k,end="")
                k+=1
            else:
                print(" ",end="")
               # continue
            j+=1
        print("")
        it+=1
        
            
    
    
def __starting_point():
    T = int(input())
    for i in range(T):
        #a = solve()
        #n = len(a)
        #for i in range(n):
         #   if i==n-1 : print(a[i])
          #  else: print(a[i],end=" ")
        (solve())
__starting_point()