def xz(jz):
res=[]
for lie in range(len(jz[0])):
tep=[]
for hang in range(len(jz)-1,-1,-1):
tep.append(jz[hang][lie])
res.append(tep)
return res
count=int(input())
jzxx=[]
jz=[]
for i in range(count):
jzxx.append(list(map(int,input().split())))
for j in range(jzxx[i][0]):
jz.append(list(map(int,input().split())))
p=-1
for i in range(count):
tep=[]
for j in range(jzxx[i][0]):
p+=1
tep.append(jz[p])
for j in range(1,jzxx[i][2]+1):
tep=xz(tep)
for j in range(len(tep)):
for k in range(len(tep[0])):
print(tep[j][k],end=' ')
print()
print()