#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
void openfarmakedata() {
freopen("in.dat","w",stdout);
}
void openforsolution() {
freopen("in.dat","r",stdin);
freopen("out.dat","w",stdout);
}
char maze[330][330];
bool stable[330][330];
int R , C;
char small_mario[13][30] = { //13 * 21
" ******** ",
" ************ ",
" ####....#. ",
" #..###.....##.... ",
" ###.......###### ",
" ........... ",
" ##*####### ",
" ####*******###### ",
"...#***.****.*###....",
"....**********##.....",
"....**** *****....",
" #### #### ",
"###### ###### "
};
char big_mario[16][30] = { // 16 * 21
" ******** ",
" ************** ",
" ####....#. ",
" #..##.....#..... ",
" #..###.....##.... ",
" ###.......###### ",
" ........... ",
" ##*###### ",
" ####*#####*##### ",
"######*******####### ",
"...#***.****.*###....",
"....**********##.....",
"...**************....",
" **** **** ",
" #### #### ",
"###### ###### "
};
char mushroom[9][30] = { //9 * 14
" ######## ",
" ##.******.## ",
"##...****...##",
"#............#",
"#..########..#",
"###..#..#..###",
" #..#..#..# ",
" #........# ",
" ######## "
};
char tube[9][30] = { // *
"####################", // 9 * 20
"#------------------#",
"#------------------#",
"####################",
" #----------# ",
" #----------# ",
" #----------# ",
" #----------# ",
" ############ "
};
char coin[6][30] = { // 6 * 5
" ### ",
"#...#",
"#.#.#",
"#.#.#",
"#...#",
" ### "
};
char block[9][30] = { // 9 * 14
"##############",
"#...#......#.#",
"##############",
"#..#....#....#",
"##############",
"#.....#......#",
"##############",
"#.#..#....#..#",
"##############"
};
char gameover[6][100] = {
"....#####.......#........#...#..#####.........###...#.....#..#####.......#####.....",
"...#...........#.#......##..##..#............#...#..#....#...#..........#.....#...",
"...#..........#..#.....#.#.#.#..#####........#...#..#...#....#####.....#######...",
"...#..###... #####....#..##..#..#............#...#..#..#.....#........#..#......",
"...#....#...#....#...#...#...#..#............#...#..#.#......#.......#....#....",
"....###.#..#.....#..#........#..#####.........###...##.......#####..#......#.."
};
void init() {
for (int i = 0;i < R;i ++) {
for (int j = 0;j < C;j ++) {
maze[i][j] = ' ';
stable[i][j] = false;
}
}
}
void ouputgameover() {
puts("");
for (int i = 0;i < 6;i ++)
puts(gameover[i]);
}
int mario_x,mario_y;
int ismariobig;
int mush_x,mush_y;
int tube1_x,tube1_y,tube2_x,tube2_y;
vector<pair<int,int> >coinlist;
vector<pair<int,int> >blocklist;
bool noTube;
int point;
char str[1000];
void output() {
for (int i = R - 1;i >= 0;i --) {
for (int j = 0;j < C;j ++) {
putchar(maze[i][j]);
}
puts("");
}
printf("Mario : %d points\n",point);
}
bool judge() {
init();
int x , y;
for (int i = 0;i < blocklist.size();i ++) {
x = blocklist[i].first;
y = blocklist[i].second;
for (int j = 0;j < 9;j ++) {
for (int h = 0;h < 14;h ++) {
maze[x + j][y + h] = block[8 - j][h];
stable[x + j][y + h] = true;
}
}
}
x = tube1_x;
y = tube1_y;
if (x != -1 && y != -1 && !noTube) {
for (int j = 0;j < 9;j ++) {
for (int h = 0;h < 20;h ++) {
if (tube[8 - j][h] == ' ') continue;
maze[x + j][y + h] = tube[8 - j][h];
stable[x + j][y + h] = true;
}
}
}
x = tube2_x;
y = tube2_y;
if (x != -1 && y != -1 && !noTube) {
for (int j = 0;j < 9;j ++) {
for (int h = 0;h < 20;h ++) {
if (tube[8 - j][h] == ' ') continue;
maze[x + j][y + h] = tube[8 - j][h];
stable[x + j][y + h] = true;
}
}
}
x = mario_x;
y = mario_y;
if (ismariobig) {
for (int j = 0;j < 16;j ++) {
for (int h = 0;h < 21;h ++) {
if (big_mario[15 - j][h] == ' ') continue;
if (maze[x + j][y + h] != ' ') return false;
maze[x + j][y + h] = big_mario[15 - j][h];
}
}
}
else {
for (int j = 0;j < 13;j ++) {
for (int h = 0;h < 21;h ++) {
if (small_mario[12 - j][h] == ' ') continue;
if (maze[x + j][y + h] != ' ') return false;
maze[x + j][y + h] = small_mario[12 - j][h];
}
}
}
for (int i = 0;i < coinlist.size();i ++) {
x = coinlist[i].first;
y = coinlist[i].second;
if (x == -1) continue;
for (int j = 0;j < 6;j ++) {
for (int h = 0;h < 5;h ++) {
if (coin[5 - j][h] == ' ') continue;
if (maze[x + j][y + h] != ' ') {
coinlist[i].first = -1;
point += 100;
j = 100;
break;
}
maze[x + j][y + h] = coin[5 - j][h];
}
}
}
x = mush_x;
y = mush_y;
if (x != -1 && y != -1) {
for (int j = 0;j < 9;j ++) {
for (int h = 0;h < 14;h ++) {
if (mushroom[8 - j][h] == ' ') continue;
if (maze[x + j][y + h] != ' ') {
ismariobig = true;
j = 100;
mush_x = -1;
break;
}
maze[x + j][y + h] = mushroom[8 - j][h];
}
}
}
return true;
}
bool judgestable() {
bool ret = false;
judge();
for (int i = 0;i < 21;i ++) {
if (stable[mario_x - 1][mario_y + i] == true) {
return true;
}
}
return false;
}
int main () {
// freopen("screen.txt","w",stdout);
while (scanf ("%d%d",&R,&C) == 2) {
bool isfirst = true;
ismariobig = false;
point = 0;
scanf ("%d%d",&mario_x,&mario_y);
scanf ("%d%d",&mush_x,&mush_y);
scanf ("%d%d",&tube1_x,&tube1_y);
scanf ("%d%d",&tube2_x,&tube2_y);
noTube = tube1_x == -1 || tube1_y == -1 || tube2_x == -1 || tube2_y == -1;
coinlist.clear();
blocklist.clear();
int n;
scanf ("%d",&n);
for (int i = 1;i <= n;i ++) {
int x , y;
scanf ("%d%d",&x,&y);
blocklist.push_back(make_pair(x,y));
}
scanf ("%d",&n);
for (int i = 1;i <= n;i ++) {
int x , y;
scanf ("%d%d",&x,&y);
coinlist.push_back(make_pair(x,y));
}
while(scanf ("%s",str)) {
for (int i = 0;str[i];i ++) {
if (str[i] == 'R') {
mario_y ++;
bool flag = judge();
if (flag == false) {
mario_y --;
}
else {
while(mario_x > 0 && judge() == true) mario_x --;
if(mario_x > 0) mario_x ++;
if (mario_x <= 0) {
ouputgameover();
break;
}
}
}
else if (str[i] == 'L') {
mario_y --;
bool flag = judge();
if (flag == false) mario_y ++;
else {
while(mario_x > 0 && judge() == true) mario_x --;
if(mario_x > 0) mario_x ++;
if (mario_x <= 0) {
ouputgameover();
break;
}
}
} else if (str[i] == 'D' && !noTube) {
if (mario_x == tube1_x + 9 && mario_y == tube1_y) {
mario_x = tube2_x + 9 ;
mario_y = tube2_y;
}
else if (mario_x == tube2_x + 9 && mario_y == tube2_y) {
mario_x = tube1_x + 9 ;
mario_y = tube1_y;
}
} else {
if (isfirst) {
isfirst = false;
}
else puts("");
judge();
output();
}
}
break;
}
}
return 0;
}
/**************************************************************
Problem: 1487
User: cust123
Language: C++
Result: Accepted
Time:80 ms
Memory:1740 kb
****************************************************************/