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
#include <bits/stdc++.h>


using namespace std;


void wypisz(vector<string>& mapa, int n, int m){
	 for (int i = 0; i < n; i++){
		 cout << mapa[i] << "\n";
	 }
	 return ;
 }
 
 
void przesun(vector<string>& mapa, int n, int m, int p){
	 vector<string> nowamapa;
	 string aha = "";
	 for (int i = 0; i < m; i++) aha.push_back('.');
	 for (int i = 0; i < n; i++) nowamapa.push_back(aha);
	 int ile = 0;
	 if (p == 0){  // gora
		 for (int j = 0; j < m; j++){
			 ile = 0;
			 for (int i = 0; i < n; i++){
				 if (mapa[i][j] != '.'){
					 nowamapa[ile][j] = mapa[i][j];
					 ile++;
				 }
			 }
		 }
	 }
	 if (p == 1){  // dol
		 for (int j = 0; j < m; j++){
			 ile = 0;
			 for (int i = n-1; i >= 0; i--){
				 if (mapa[i][j] != '.'){
					 nowamapa[n-ile-1][j] = mapa[i][j];
					 ile++;
				 }
			 }
		 }
	 }
	 if (p == 2){  // lewo
		 for (int i = 0; i < n; i++){
			 ile = 0;
			 for (int j = 0; j < m; j++){
				 if (mapa[i][j] != '.'){
					 nowamapa[i][ile] = mapa[i][j];
					 ile++;
				 }
			 }
		 }
	 }
	  if (p == 3){  // prawo
		 for (int i = 0; i < n; i++){
			 ile = 0;
			 for (int j = m-1; j >= 0; j--){
				 if (mapa[i][j] != '.'){
					 nowamapa[i][m-1-ile] = mapa[i][j];
					 ile++;
				 }
			 }
		 }
	 }
	 mapa = nowamapa;
 }



int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector<string> mapa;
	string s;
	for (int i = 0; i < n; i++){
		cin >> s;
		mapa.push_back(s);
	}
	int k;
	cin >> k;
	cin >> s;
	set<char> xd;
	vector<char> posy;
	for (int i = k-1; i >= 0; i--){
		if (!posy.size()){
			posy.push_back(s[i]);
			continue;
		}
		if (s[i] == 'L'){
			if (posy.back() == s[i] || (posy.back() == 'P' && posy.size() > 100)) continue;
			posy.push_back(s[i]);
		}
		if (s[i] == 'P'){
			if (posy.back() == s[i] || (posy.back() == 'L' && posy.size() > 100)) continue;
			posy.push_back(s[i]);
		}
		if (s[i] == 'G'){
			if (posy.back() == s[i] || (posy.back() == 'D' && posy.size() > 100)) continue;
			posy.push_back(s[i]);
		}
		if (s[i] == 'D'){
			if (posy.back() == s[i] || (posy.back() == 'G' && posy.size() > 100)) continue;
			posy.push_back(s[i]);
		}
		if (posy.size() > 500) break;
	}
		
		
	reverse(posy.begin(), posy.end());
		 
	for (auto u: posy){
		if (u == 'G') przesun(mapa,n,m,0);
		if (u == 'D') przesun(mapa,n,m,1);
		if (u == 'L') przesun(mapa,n,m,2);
		if (u == 'P') przesun(mapa,n,m,3);
	}
	wypisz(mapa,n,m);
	return 0;
}