x=list(map(int,input().split()))
a=[]
for i in range(x[0]):
y=list(map(int,input().split()))
a.append(y)
z=list(map(int,input().split()))
##print(x)
##print(a)
##print(z)
def rotate(data):
#p=[ ['']*data[1] for i in range(data[0])]
final=[]
for i in range(-1,-len(data[0])-1,-1):
row=[]
for n in range(len(data)):
row.append(data[n][i])
final.append(row)
return final
##a=rotate(a)
def downup(data):
m=[]
for i in range(-1,-len(data)-1,-1):
m.append(data[i])
return m
##a=downup(a)
##print(a)
#0 = rotate,1 = dowup
for i in range(-1,-len(z)-1,-1):
if z[i]==0:
a=rotate(a)
elif z[i]==1:
a=downup(a)
print(len(a),len(a[0]))
for i in range(len(a)):
for k in range(len(a[0])):
print(a[i][k],end=' ')
print()
x=list(map(int,input().split()))
a=[]
for i in range(x[0]):
y=list(map(int,input().split()))
a.append(y)
z=list(map(int,input().split()))
##print(x)
##print(a)
##print(z)
def rotate(data):
#p=[ ['']*data[1] for i in range(data[0])]
final=[]
for i in range(-1,-len(data[0])-1,-1):
row=[]
for n in range(len(data)):
row.append(data[n][i])
final.append(row)
return final
##a=rotate(a)
def downup(data):
m=[]
for i in range(-1,-len(data)-1,-1):
m.append(data[i])
return m
##a=downup(a)
##print(a)
#0 = rotate,1 = dowup
for i in range(-1,-len(z)-1,-1):
if z[i]==0:
a=rotate(a)
elif z[i]==1:
a=downup(a)
print(len(a),len(a[0]))
for i in range(len(a)):
for k in range(len(a[0])):
print(a[i][k],end=' ')
print()
1. 輸入有多比測資,所以要使用while迴圈和try
2. 每一行最後不能有空格