#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include<functional>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int N=50+5;
const int M=150005;
ll power(ll a,int b,ll c){ll ans=1;while(b){if(b%2==1){ans=(ans*a)%c;b--;}b/=2;a=a*a%c;}return ans;}
struct man
{
int x,y;
int num;
};
int n,m,k,I,J;
char w[N][N];
char p[N];
int d[4][2]={-1,0,1,0,0,-1,0,1};
int a[1005];
int vis[N][N][1005];
bool check(int sx,int sy,int ex,int ey)
{
if(sx==ex){
for(int i=min(sy,ey);i<=max(sy,ey);i++)if(w[sx][i]==‘X‘)return false;
}
if(sy==ey){
for(int i=min(sx,ex);i<=max(sx,ex);i++)if(w[i][sy]==‘X‘)return false;
}
return true;
}
void bfs()
{
queue<man>q;
man s;s.num=0;s.x=I;s.y=J;
q.push(s);
vis[I][J][0]=1;
while(!q.empty()){
man t=q.front();q.pop();//printf("%d %d %d\n",t.x+1,t.y+1,t.num);
if(t.num==k){w[t.x][t.y]=‘*‘;continue;}
for(int i=1;i<=50;i++){
int j=a[t.num];
int xx=t.x+i*d[j][0];
int yy=t.y+i*d[j][1];
if(xx<0||xx>=n||yy<0||yy>=m)break;
if(check(t.x,t.y,xx,yy)&&vis[xx][yy][t.num+1]==0){
man kk;kk.num=t.num+1;kk.x=xx;kk.y=yy;
q.push(kk);
vis[xx][yy][t.num+1]=1;
}
}
}
}
int main()
{
memset(vis,0,sizeof(vis));
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)scanf("%s",w[i]);
for(int i=0;i<n;i++)for(int j=0;j<m;j++)if(w[i][j]==‘*‘){I=i;J=j;w[i][j]=‘.‘;break;}
scanf("%d",&k);
for(int i=0;i<k;i++){
scanf("%s",p);
if(p[0]==‘N‘)a[i]=0;
if(p[0]==‘S‘)a[i]=1;
if(p[0]==‘W‘)a[i]=2;
if(p[0]==‘E‘)a[i]=3;
}
bfs();
for(int i=0;i<n;i++)printf("%s\n",w[i]);
return 0;
}