package apcs;
import java.util.Scanner;
//b266矩陣翻轉
public class b266 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
rowColumn rc = new rowColumn();
do {
rc.r = sc.nextInt();
} while (1 > rc.r || 10 < rc.r);
do {
rc.c = sc.nextInt();
} while (1 > rc.c || 10 < rc.c);
do {
rc.m = sc.nextInt();
} while (1 > rc.m || 10 < rc.m);
rc.b = new int[rc.r][rc.c];
for (int i = 0; i < rc.b.length; i++) {
for (int j = 0; j < rc.b[i].length; j++) {
do {
rc.b[i][j] = sc.nextInt();
} while (rc.b[i][j] < 0 || rc.b[i][j] > 9);
}
}
int mk;
for (int k = 0; k < rc.m; k++) {
mk = sc.nextInt();
if (mk == 0 || mk == 1) {
if (mk == 1) {
rc.flip(rc.b);
} else if (mk == 0) {
rc.flip(rc.b);
rc.turn(rc.b);
}
} else {
k--;
}
}
rc.output();
}
}
class rowColumn {
int r;
int c;
int m;
int a[][];
static int b[][];
void flip(int[][] b) {
int[][] temp = new int[b.length][b[0].length];
int i = 0;
int j = b.length - 1;
while (i != j && i < j) {
temp[j] = b[i];
temp[i] = b[j];
i++;
j--;
}
if (i == j) {
temp[i] = b[i];
}
this.b = temp;
}
void turn(int[][] b) {
int[][] temp = new int[b[0].length][b.length];
for (int i = 0; i < b.length; i++) {
for (int j = 0; j < b[i].length; j++) {
temp[j][i] = b[i][j];
}
}
this.b = temp;
}
void output() {
System.out.printf("%d" + " %d\n", b.length, b[0].length);
for (int i = 0; i < b.length; i++) {
for (int j = 0; j < b[i].length; j++) {
System.out.printf("%d", b[i][j]);
if (j == b[i].length - 1) {
System.out.printf("\n");
} else {
System.out.printf(" ");
}
}
}
}
}