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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <iostream>
using namespace std;

int main() {
	std::ios::sync_with_stdio(false);
	int x, y, steps;
	cin >> y >> x;
	char t[y][x], d;
	
	for (int ys = 0; ys < y; ys++) {
		for (int xs = 0; xs < x; xs++) {
			cin >> t[ys][xs];
		}
	}
	
	
	// for (int ys = 0; ys < y; ys++) {
	// 	for (int xs = 0; xs < x; xs++) {
	// 		cout << t[ys][xs];
	// 	}
	// 	cout << endl;
	// }
	// cout << endl;
	
	
	cin >> steps;
	char tmp;
	
	char s[steps];
	
	cin >> s[0];
	int last = 0;
	char lastLP = 'm', lastGD = 'm';
	if (s[0] == 'L') {
		lastLP = 'L';
	} else if (s[0] == 'P') {
		lastLP = 'P';
	} else if (s[0] == 'G') {
		lastGD = 'G';
	} else if (s[0] == 'D') {
		lastGD = 'D';
	}
	for (int i = 1; i < steps; i++) {
		cin >> d;
		// cout << "D = " << d << endl;
		if (s[last] != d) {
			// cout << "lastLP = " << lastLP << endl;
			// cout << "lastGD = " << lastGD << endl;
			if (d == 'L' || d == 'P') {
				if (lastLP != d) {
					lastLP = d;
					if (s[last] == 'L' || s[last] == 'P') {
						s[last] = d;
					} else {
						++last;
						s[last] = d;
					}
				}
			} else if (d == 'G' || d == 'D') {
				if (lastGD != d) {
					lastGD = d;
					if (s[last] == 'G' || s[last] == 'D') {
						s[last] = d;
					} else {
						++last;
						s[last] = d;
					}
				}
			}
				
		}
		// cout << "lastLP = " << lastLP << endl;
		// cout << "lastGD = " << lastGD << endl;
		
	}
	
	// cout << "steps = " << last << endl;
	// for (int i = 0; i <= last; i++) {
	// 	cout << s[i] << " ";
	// }
	// cout << endl;
	
	for (int i = 0; i <= last; i++) {
		// cin >> d;
		d = s[i];
		if (d == 'L') {
			for (int ys = 0; ys < y; ys++) {
				int counter = 0;
				for (int xs = 0; xs < x; xs++) {
					if (t[ys][xs] != '.') {
						tmp = t[ys][xs];
						t[ys][xs] = '.';
						t[ys][counter] = tmp;
						++counter;
					}
				}
			}
		} else if (d == 'P') {
			for (int ys = 0; ys < y; ys++) {
				int counter = x - 1;
				for (int xs = x - 1; xs >= 0; xs--) {
					if (t[ys][xs] != '.') {
						tmp = t[ys][xs];
						t[ys][xs] = '.';
						t[ys][counter] = tmp;
						--counter;
					}
				}
			}
		} else if (d == 'D') {
			for (int xs = 0; xs < x; xs++) {
				int counter = y - 1;
				for (int ys = y - 1; ys >= 0; ys--) {
					if (t[ys][xs] != '.') {
						tmp = t[ys][xs];
						t[ys][xs] = '.';
						t[counter][xs] = tmp;
						--counter;
					}
				}
			}
		} else if (d == 'G') {
			for (int xs = 0; xs < x; xs++) {
				int counter = 0;
				for (int ys = 0; ys < y; ys++) {
					if (t[ys][xs] != '.') {
						tmp = t[ys][xs];
						t[ys][xs] = '.';
						t[counter][xs] = tmp;
						++counter;
					}
				}
			}
		}
	}
	
	
	
	
	for (int ys = 0; ys < y; ys++) {
		for (int xs = 0; xs < x; xs++) {
			cout << t[ys][xs];
		}
		cout << endl;
	}
	cout << endl;
	
	
}