#include <iostream>
using namespace std;
int B[11][11], A[11][11], act[11];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int r, c, m;
while (cin >> r >> c >> m){
for (int i=1; i<=r; i++){
for ( int j=1; j<=c; j++ ){
cin >> B[i][j];
}
}
for (int i=0; i<m; i++){
cin >> act[i];
}
for (int k=m-1; k>=0; k--){
for (int i=1; i<=r; i++){
for (int j=1; j<=c; j++){
A[i][j]=B[i][j];
}
}
if (act[k]==0){
for (int j=1; j<=c; j++){
for (int i=1; i<=r; i++){
B[c-j+1][i]=A[i][j];
}
}
swap(r,c);
}
else {
for (int i=1; i<=r; i++){
for (int j=1; j<=c; j++){
B[r-i+1][j]=A[i][j];
}
}
}
}
cout << r <<" "<< c <<endl;
for (int i=1; i<=r; i++){
for (int j=1; j<=c; j++){
if (j>1){
cout <<" ";
}
cout << B[i][j];
}
cout <<endl;
}
}
return 0;
}