#include<bits/stdc++.h>
#define map mapp
#define ll long long
using namespace std;
const int fx[]={0,-1,+1,0,0};
const int fy[]={0,0,0,-1,+1};
int n,m,s[1005];
bool pd[60][60][7];
char map[60][60];
struct uc{
short x,y,step;
};
queue <uc> q;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>map[i][j];
if(map[i][j]=='*'){
q.push({i,j,1});
map[i][j]='.';
}
}
}
int T;cin>>T;
for(int i=1;i<=T;i++){
string c; cin>>c;
if(c=="NORTH") s[i]=1;
if(c=="SOUTH") s[i]=2;
if(c=="WEST") s[i]=3;
if(c=="EAST") s[i]=4;
}
while(!q.empty()){
uc tmp=q.front();q.pop();
if(tmp.step==T+1){
map[tmp.x][tmp.y]='*';
continue;
}
int x=tmp.x+fx[s[tmp.step]];
int y=tmp.y+fy[s[tmp.step]];
while(!(x<1||y<1||x>n||y>m||map[x][y]=='X')){
if(pd[x][y][tmp.step]==0){
pd[x][y][tmp.step]=1;
q.push({x,y,tmp.step+1});
}
x+=fx[s[tmp.step]];
y+=fy[s[tmp.step]];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
cout<<map[i][j];
cout<<endl;
}
return 0;
}