1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include<cstdio>

#define N 505
#define K 500005

char tablica[N][N];
char ruchy[K];

char opt_ruchy[K];

char rzad[N];


void print(int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			printf("%c", tablica[i][j]);
		}
		printf("\n");
	}
}

int main() {
	int n, m;
	scanf("%d %d\n", &n, &m);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			tablica[i][j] = fgetc(stdin);
		}
		fgetc(stdin);
	}

	int k;
	scanf("%d\n", &k);

	for (int i = 0; i < k; i++) {
		ruchy[i] = fgetc(stdin);
	}

	int liczba = 0;
	for (int i = 0; i < k; i++) {
		if (
				((ruchy[i] == 'L' || ruchy[i] == 'P') && (ruchy[i+1] == 'L' || ruchy[i+1] == 'P'))
				|| ((ruchy[i] == 'G' || ruchy[i] == 'D') && (ruchy[i+1] == 'G' || ruchy[i+1] == 'D'))
		) {
			continue;
		} else {
			opt_ruchy[liczba++] = ruchy[i];
		}
	}

//	for (int i = 0; i < liczba; i++) {
//		printf("%c", opt_ruchy[i]);
//	}
//	printf("\n");

	for (int i = 0; i < liczba; i++) {
		if (opt_ruchy[i] == 'G' || opt_ruchy[i] == 'D') {
			for (int x = 0; x < m; x++) {
				int liczba = 0;
				for (int y = 0; y < n; y++) {
					if (tablica[y][x] != '.') {
						rzad[liczba++] = tablica[y][x];
					}
				}

				if (opt_ruchy[i] == 'G') {
					for (int y = 0; y < n; y++) {
						if (y < liczba) {
							tablica[y][x] = rzad[y];
						} else {
							tablica[y][x] = '.';
						}
					}

				} else {
					for (int y = 0; y < n; y++) {
						if (y < n - liczba) {
							tablica[y][x] = '.';
						} else {
							tablica[y][x] = rzad[y + liczba - n];
						}
					}
				}
			}
		}

		if (opt_ruchy[i] == 'L' || opt_ruchy[i] == 'P') {
			for (int x = 0; x < n; x++) {
				int liczba = 0;
				for (int y = 0; y < m; y++) {
					if (tablica[x][y] != '.') {
						rzad[liczba++] = tablica[x][y];
					}
				}

				if (opt_ruchy[i] == 'L') {
					for (int y = 0; y < m; y++) {
						if (y < liczba) {
							tablica[x][y] = rzad[y];
						} else {
							tablica[x][y] = '.';
						}
					}

				} else {
					for (int y = 0; y < m; y++) {
						if (y < m - liczba) {
							tablica[x][y] = '.';
						} else {
							tablica[x][y] = rzad[y + liczba - m];
						}
					}
				}
			}
		}
	}

	print(n, m);

	return 0;
}