#include<bits/stdc++.h>
using namespace std;
int n,m,t,cnt=0;
char a[100][100];
string s;
queue<int>x;
queue<int>y;
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]=='*')x.push(i),y.push(j),a[i][j]='.';
}
}
scanf("%d",&t);
while(t--){
int xx=x.front(),yy=y.front();
cin>>s;
if(t==1){
if(s=="EAST"){
while(yy++<=m&&a[xx][yy]!='X')x.push(xx),y.push(yy),cnt++;
}
if(s=="SOUTH"){
while(xx++<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy),cnt++;
}
if(s=="WEST"){
while(yy--<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy),cnt++;
}
if(s=="NORTH"){
while(xx--<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy),cnt++;
}
}
else{
if(s=="EAST"){
while(yy++<=m&&a[xx][yy]!='X')x.push(xx),y.push(yy);
}
if(s=="SOUTH"){
while(xx++<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy);
}
if(s=="WEST"){
while(yy--<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy);
}
if(s=="NORTH"){
while(xx--<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy);
}
}
x.pop(),y.pop();
}
cnt-=2;
while(cnt--){
a[x.front()][y.front()]='*',x.pop(),y.pop();
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<a[i][j];
}
cout<<endl;
}
return 0;
}
https://www.luogu.com.cn/record/91211604