#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int R,C,M;
while(cin >> R >> C >> M){
int i,j,V[10][10]={0},W[10][10]={0};
for(i=0;i<R;i++){
for(j=0;j<C;j++){
cin >> V[i][j];
}
}
int m,chk=0;
while(M && cin >> m){
if(m==0){
int K=(R>=C)?R:C;
for(i=0;i<K;i++){
for(j=0;j<K;j++){
if(chk%2==0) W[i][j]=V[R-1-j][i];
else if(chk%2==1) V[i][j]=W[R-1-j][i];
}
}
swap(R,C);
chk++;
}
else if(m==1){
for(i=0;i<R;i++){
for(j=0;j<C;j++){
if(chk%2==0) W[R-1-i][j]=V[i][j];
else if(chk%2==1) V[R-1-i][j]=W[i][j];
}
}
chk++;
}
M--;
}
cout << R << " " << C << endl;
for(i=0;i<R;i++){
for(j=0;j<C-1;j++){
if(chk%2==0) cout << V[i][j] << " ";
if(chk%2==1) cout << W[i][j] << " ";
}
if(chk%2==0) cout << V[i][C-1];
if(chk%2==1) cout << W[i][C-1];
cout << endl;
}
}
}