def func1(func1a,func1f):
for func1_i in range(func1f):
for func1_j in range(1,func1a+1):
print(str(func1_j)*func1_j)
for func1_j in range(func1a-1,0,-1):
print(str(func1_j)*func1_j)
print("")
L1=[]
a=int(input())
s1=input()
for i in range(a):
L1=[]
L1.append(int(input()))
L1.append(int(input()))
func1(L1[0],L1[1])