def fly(a):
r = len(a)
return [a[r-1-i] for i in range(r)]
def lop(a):
r,c = len(a),len(a[0])
return [[a[i][j]for i in range(r)]for j in range(c)]
a = []
r,c,m = map(int,input().split())
for i in range(r):
j = list(map(int,input().split()))
a.append(j)
p = list(map(int,input().split()))
for i in p[::-1]:
if i ==0:a = lop(a)
a = fly(a)
print(r,c)
for i in range(len(a)):
print(*a[i])