import java.io.*;
import java.util.*;
public class Main {
static StringBuilder sb = new StringBuilder();
static int[][] rotation;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int R = Integer.parseInt(st.nextToken());
rotation = new int[N][M];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine(), " ");
for (int j = 0; j < M; j++) {
rotation[i][j] = Integer.parseInt(st.nextToken());
}
}
st = new StringTokenizer(br.readLine(), " ");
while(st.hasMoreTokens()) {
int tc = Integer.parseInt(st.nextToken());
N = rotation.length;
M = rotation[0].length;
switch (tc) {
case 1: {
for (int i = 0; i < N / 2 + N % 2; i++) {
for (int j = 0; j < M; j++) {
int temp = rotation[i][j];
rotation[i][j] = rotation[N - i - 1][j];
rotation[N - i - 1][j] = temp;
}
}
break;
}
case 2: {
for (int i = 0; i < N; i++) {
for (int j = 0; j < M / 2 + M % 2; j++) {
int temp = rotation[i][j];
rotation[i][j] = rotation[i][M - 1 - j];
rotation[i][M - 1 - j] = temp;
}
}
break;
}
case 3: {
int[][] array_R90 = new int[M][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
int temp = rotation[i][j];
array_R90[j][N - i - 1] = temp;
}
}
rotation = new int[M][N];
rotation = array_R90;
break;
}
case 4: {
int[][] array_L90 = new int[M][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
int temp = rotation[i][j];
array_L90[M - j - 1][i] = temp;
}
}
rotation = new int[M][N];
rotation = array_L90;
break;
}
case 5: {
int[][] array_R4 = new int[N][M];
for (int i = 0; i < N / 2; i++) {
for (int j = 0; j < M / 2; j++) {
array_R4[i][M/2+j] = rotation[i][j];
}
}
for (int i = 0; i < N / 2; i++) {
for (int j = M/2; j < M; j++) {
array_R4[N/2+i][j] = rotation[i][j];
}
}
for (int i = N/2; i < N; i++) {
for (int j = M/2; j < M; j++) {
array_R4[i][j-M/2] = rotation[i][j];
}
}
for (int i = N/2; i < N; i++) {
for (int j = 0; j < M / 2; j++) {
array_R4[i-N/2][j] = rotation[i][j];
}
}
rotation = new int[N][M];
rotation = array_R4;
break;
}
case 6: {
int[][] array_L4 = new int[N][M];
for (int i = 0; i < N / 2; i++) {
for (int j = 0; j < M / 2; j++) {
array_L4[i+N/2][j] = rotation[i][j];
}
}
for (int i = 0; i < N / 2; i++) {
for (int j = M/2; j < M; j++) {
array_L4[i][j-M/2] = rotation[i][j];
}
}
for (int i = N/2; i < N; i++) {
for (int j = M/2; j < M; j++) {
array_L4[i-N/2][j] = rotation[i][j];
}
}
for (int i = N/2; i < N; i++) {
for (int j = 0; j < M / 2; j++) {
array_L4[i][j+M/2] = rotation[i][j];
}
}
rotation = new int[N][M];
rotation = array_L4;
break;
}
}
}
System.out.println(printArray(rotation));
}
static String printArray(int[][] a) {
sb.setLength(0);
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
sb.append(a[i][j]).append(" ");
}
sb.append("\n");
}
sb.setLength(sb.length()-1);
return sb.toString();
}
}