#include <iostream>
#include <cmath>
using namespace std;
int a[55][55];
int dx[4]={0,-1,0,1},
dy[4]={-1,0,1,0};
int fx[4]={2,1,4,3};
int h[2550][8];
int sx,sy,zx,zy;
int n,m,flag=0;
int bz[55][55];
void findway(int k)
{
if(k!=1)
{
findway(h[k][7]);
}
cout<<h[k][1]<<" "<<h[k][2]<<"->";
return;
}
void bfs(int p,int q,int b)
{
int x,y,t,w,r;
bz[p][q]=1;
t=0;
w=1;
h[1][1]=p;
h[1][2]=q;
h[1][3]=b;
h[1][4]=0;
h[1][7]=0;
do
{
t++;
for(int i=0;i<4;i++)
{
if(fx[i]==h[t][3])r=0;
else if(abs(fx[i]-h[t][3])==1||abs(fx[i]-h[t][3])==3)r=1;
else r=2;
for(int j=1;j<=3;j++)
{
x=h[t][1]+dx[i]*j;
y=h[t][2]+dy[i]*j;
if(x>=0&&x<n&&y>=0&&y<m&&bz[x][y]==0)
{
if(a[x][y]==1)break;
w++;
bz[x][y]=1;
h[w][1]=x;
h[w][2]=y;
h[w][3]=fx[i];
h[w][4]=h[t][4]+r+1;
h[w][7]=t;
if(x==zx&&y==zy)
{
cout<<h[w][4]<<endl;
findway(w);
flag=1;
return;
}
}
}
}
}while(t<w);
}
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
int s;
cin>>s;
if(s==1)
{
a[i][j]=1;
a[i][j+1]=1;
a[i+1][j]=1;
a[i+1][j+1]=1;
}
}
}
n++;
m++;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cin>>sx>>sy>>zx>>zy;
char u;
int f;
cin>>u;
if(u=='N')f=1;
if(u=='S')f=3;
if(u=='W')f=2;
if(u=='E')f=4;
bfs(sx,sy,f);
if(!flag)
{
cout<<"-1";
}
return 0;
}