n = int(input())
x = input()
for i in range (1,n+1):
A = int(input())
F = int(input())
for j in range(1,F+1):
for k in range(1,A+1):
print(str(k)*k)
for k in range(A-1,0,-1):
print(str(k)*k)
print()