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.

Starter code:

Solutions:
# cook your dish here
for _ in range(int(input())):
    n = int(input())
    count = 1
    l = 3*(n-1)
    i = 0
    if n==1:
        print(1)
        continue
    while count<=l-n:
        for j in range(i+1):
            if j==i:
                print(count)
                count += 1
            elif j==0:
                print(count,end="")
                count += 1
            else:
                print(" ",end="")    
        i+=1
    while count<=l:
        print(count,end="")
        count += 1
    print()

t = int(input())
for _ in range(t):
    k = int(input())
    count=1
    for i in range(k):
        for j in range(i+1):
            if i<k-1:
                if i==j or j==0:
                    print(count,end='')
                    count += 1
                else:
                    print(' ',end='')
            else:
                print(count,end='')
                count+=1
        print()
                

# 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()

def solve(n):
    c= 1
    r = list(range(1,n+1))
    for i in r:
        x = ''
        if 3<=i<n:
            x+=str(c)
            c+=1
            for j in range(i-2):
                x+=' '
            x+=str(c)
            c+=1
        else:
            for j in range(i):
                x+=str(c)
                c+=1
        print(x)

def main():
    t = int(input())
    for i in range(t):
        n = int(input())
        solve(n)


main()


def f(n):
    if n==1:
        return print(1)
    
    p = 2
    print(1)
    
    line = 2
    while line < n:
        print(p, " "*(line-2), p+1, sep="")
        p += 2
        line += 1
    
    for i in range(n):
        print(p, end="")
        p += 1
    print()

t = int(input())
answers = list()
for _ in range(t):
    n = int(input())
    answers.append(n)

for answer in answers:
    f(answer)

for _ in range(int(input())):
    n=int(input())
    a=0
    xx=2
    if n==1:
        print('1')
    elif n==2:
        print('1')
        print('23')
    else:    
        print('1')
        for _ in range(2,n):
            print(xx,end="")
            xx+=1
            if a>0:
                print(' '*a,end="")
            a+=1
            print(xx)
            xx+=1
        # xx+=1    
        for _ in range(1,n+1):
            print(xx,end="")
            xx+=1
        print()    
            
            
         

import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
inp = lambda: list(map(int,sys.stdin.readline().rstrip("\r\n").split()))
#______________________________________________________________________________________________________
# from math import *
# from bisect import *
# from heapq import *
# from collections import defaultdict as dd
# from collections import OrderedDict as odict
# from collections import Counter as cc
# from collections import deque
# sys.setrecursionlimit(2*(10**5)+100) this is must for dfs
# mod = 10**9+7; md = 998244353
# ______________________________________________________________________________________________________
# segment tree for range minimum query
# sys.setrecursionlimit(10**5)
# n = int(input())
# a = list(map(int,input().split()))
# st = [float('inf') for i in range(4*len(a))]
# def build(a,ind,start,end):
#   if start == end:
#       st[ind] = a[start]
#   else:
#       mid = (start+end)//2
#       build(a,2*ind+1,start,mid)
#       build(a,2*ind+2,mid+1,end)
#       st[ind] = min(st[2*ind+1],st[2*ind+2])
# build(a,0,0,n-1)
# def query(ind,l,r,start,end):
#   if start>r or end<l:
#       return float('inf')
#   if l<=start<=end<=r:
#       return st[ind]
#   mid = (start+end)//2
#   return min(query(2*ind+1,l,r,start,mid),query(2*ind+2,l,r,mid+1,end))
# ______________________________________________________________________________________________________
# Checking prime in O(root(N))
# def isprime(n):
#     if (n % 2 == 0 and n > 2) or n == 1: return 0
#     else:
#         s = int(n**(0.5)) + 1
#         for i in range(3, s, 2):
#             if n % i == 0:
#                 return 0
#         return 1
# def lcm(a,b):
#   return (a*b)//gcd(a,b)
# ______________________________________________________________________________________________________
# nCr under mod
# def C(n,r,mod):
#   if r>n:
#       return 0
#   num = den = 1
#   for i in range(r):
#       num = (num*(n-i))%mod
#       den = (den*(i+1))%mod
#   return (num*pow(den,mod-2,mod))%mod
# M = 10**5 +10
# ______________________________________________________________________________________________________
# For smallest prime factor of a number
# M = 1000010
# pfc = [i for i in range(M)]
# def pfcs(M):
#   for i in range(2,M):
#       if pfc[i]==i:
#           for j in range(i+i,M,i):
#               if pfc[j]==j:
#                   pfc[j] = i
#   return
# pfcs(M)
# ______________________________________________________________________________________________________
tc = 1
tc, = inp()
# a = [0,1]
# for i in range(100000):
#     a.append(a[-1]+a[-2])
for _ in range(tc):
    n, = inp()
    if n==1:
        print(1)
        continue
    c = 1
    print(1)
    c+=1
    for i in range(n-2):
        print(str(c)+' '*(i)+str(c+1))
        c+=2
    print(*[c+i for i in range(n)],sep = "")

for _ in range(int(input())):
    n=int(input())
    if(n==1):
        print("1")
        continue
    print("1")
    r=2
    for i in range(n-2):
        t=str(r)
        t+=" "*i
        r+=1
        t+=str(r)
        r+=1
        print(t)
    for i in range(n):
        print(r,end="")
        r+=1
    print()

from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353
def inp(): return stdin.readline().strip()
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def smp(): return map(str, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
def remadd(x, y): return 1 if x%y else 0
def ceil(a,b): return (a+b-1)//b

def isprime(x):
    if x<=1: return False
    if x in (2, 3): return True
    if x%2 == 0: return False
    for i in range(3, int(sqrt(x))+1, 2):
        if x%i == 0: return False
    return True
    
for _ in range(int(inp())):
    n = int(inp())
    k = 1
    for i in range(1, n+1):
        for j in range(i):
            if j==0 or j==i-1 or i==n: 
                print(k, end="")
                k+=1
            else: print(" ", end="")
        print()