#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;
inline void write(int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
inline int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
char s[50][50];
char a[1005];
int m,cnt=0;
int r,c,xx,yy;
inline void dfs(int step,int x,int y)
{
if(step==cnt+1)
{
s[x][y]='*';
}
if(s[x][y]=='*')
return;
if(a[step]=='N')
{
int xx=x;
--xx;
while(s[xx][y]=='.'||s[xx][y]=='*')
{
dfs(step+1,xx,y);
--xx;
}
}
if(a[step]=='S')
{
int xx=x;
++xx;
while(s[xx][y]=='.'||s[xx][y]=='*')
{
dfs(step+1,xx,y);
++xx;
}
}
if(a[step]=='W')
{
int yy=y;
--yy;
while(s[x][yy]=='.'||s[x][yy]=='*')
{
dfs(step+1,x,yy);
--yy;
}
}
if(a[step]=='E')
{
int yy=y;
++yy;
while(s[x][yy]=='.'||s[x][yy]=='*')
{
dfs(step+1,x,yy);
++yy;
}
}
}
int main()
{
ios::sync_with_stdio(false);
a[0]='#';
r=read(),c=read();
for(int i=1;i<=r;++i)
{
for(int j=1;j<=c;++j)
{
cin>>s[i][j];
if(s[i][j]=='*')
xx=i,yy=j,s[i][j]='.';
}
}
m=read();
for(int i=1;i<=m;++i)
{
string s;
cin>>s;
char c=s[0];
if(c!=a[cnt])
a[++cnt]=c;
}
dfs(1,xx,yy);
for(int i=1;i<=r;++i)
{
for(int j=1;j<=c;++j)
{
putchar(s[i][j]);
}
putchar('\n');
}
return 0;
}