#include <stdio.h>
#include <string.h>
int main() {
// Write C code here
char name[12], command[3];
// Increased size of command to accommodate 2 characters and null terminator
int height, width;
while (scanf("%s %d %d %s", name, &width, &height, command) != EOF) {
// Read the image
char image[height][width];
for (int i = 0; i < height; i++) {
scanf("%s", image[i]);
}
printf("%s\n", name);
if (command[0] == 'R'&&command[1]!='I') {
for (int i = 0; i < height; i++) {
for (int j = width; j > 0; j--) {
printf("%c", image[i][j - 1]);
}
printf("\n");
}
} else if (command[0] == 'I' && command[1] == 'R'||command[0] == 'R' && command[1] == 'I') {
// Modified condition to check both characters
for (int i = height; i > 0; i--) {
for (int j = width; j > 0; j--) {
printf("%c", image[i - 1][j - 1]);
}
printf("\n");
}
} else if(command[0]=='I'&&command[1]!='R') {
for (int i = height; i > 0; i--) {
for (int j = 0; j <width; j++) {
printf("%c", image[i - 1][j]);
}
printf("\n");
}
}
}
return 0;
}