#include <iostream>
using namespace std;
int **matrix;
int r, c;
void output()
{
cout << r << " " << c << endl;
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
cout << matrix[i][j];
if(j + 1 != c) cout << " ";
}
cout << endl;
}
}
void my_swap(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}
void flip()
{
for(int i = 0; i < r / 2; i++)
for(int j = 0; j < c; j++)
my_swap(matrix[i][j], matrix[r - i - 1][j]);
}
void spin()
{
my_swap(r, c);
int **newMatrix = new int*[r];
for(int i = 0; i < r; i++)
{
newMatrix[i] = new int[c];
for(int j = 0; j < c; j++)
newMatrix[i][j] = matrix[j][r - 1 - i];
}
matrix = newMatrix;
}
int main()
{
int m;
cin >> r >> c >> m;
matrix = new int*[r];
for(int i = 0; i < r; i++)
{
matrix[i] = new int[c];
for(int j = 0; j < c; j++)
cin >> matrix[i][j];
}
int order[m];
for(int i = m - 1; i >= 0; i--)
cin >> order[i];
for(int i = 0; i < m; i++)
if(order[i] == 0) spin();
else flip();
output();
return 0;
}