r,c,m=map(int,input().split())
l=[]
for i in range(r):
l.append(list(map(int,input().split())))
change=list(map(int,input().split()))
# l=[[1, 1], [3,1], [1,2]]
# change=[1, 0, 0]
change.reverse()
def invert(l):
# l=[[1, 1], [3,1], [1,2]]
if len(l)%2==1:
for i in range(int((len(l)-1)/2)):
l[i],l[len(l)-i-1]=l[len(l)-i-1],l[i]
else:
for i in range(int(len(l)/2)):
l[i],l[len(l)-i-1]=l[len(l)-i-1],l[i]
return l
def spin(l):
# l=[[1, 1], [3,1], [1,2]]
g=[]
l.reverse
for i in range(len(l[0])):
g.append(list(t[len(l[0])-1-i] for t in l))
return g
for i in change:
if i==0:
l=spin(l)
else:
l=invert(l)
print(len(l),len(l[0]))
for i in range(len(l)):
print(" ".join(str(i) for i in l[i]))