#include<bits/stdc++.h>
using namespace std;
char str[15][15];
bool color[15][15];
int counter,x,y,counter1,flag;
int dfs(int i,int j)
{
if(color[i][j]==true)
{
x=i,y=j;
return 1;
}
if(str[i][j]=='W')
{
color[i][j] = true;
counter++;
dfs(i,j-1);
}
else if(str[i][j]=='E')
{
color[i][j] = true;
counter++;
dfs(i,j+1);
}
else if(str[i][j]=='S')
{
color[i][j] = true;
counter++;
dfs(i+1,j);
}
else if(str[i][j]=='N')
{
color[i][j] = true;
counter++;
dfs(i-1,j);
}
else
{
return 2;
}
}
int dfs1(int i,int j)
{
if(color[i][j]==true)
{
return 1;
}
if(str[i][j]=='W')
{
color[i][j] = true;
counter1++;
dfs1(i,j-1);
}
else if(str[i][j]=='E')
{
color[i][j] = true;
counter1++;
dfs1(i,j+1);
}
else if(str[i][j]=='S')
{
color[i][j] = true;
counter1++;
dfs1(i+1,j);
}
else if(str[i][j]=='N')
{
color[i][j] = true;
counter1++;
dfs1(i-1,j);
}
}
int main()
{
int r,c,enter,i,a;
while(scanf("%d%d%d",&r,&c,&enter)&&r&&c&&enter)
{
getchar();
for(i=0; i<r; i++)
{
gets(str[i]);
}
counter = 0;
flag = dfs(0,enter-1);
if(flag == 1)
{
memset(color,false,sizeof color);
counter1 = 0;
a = dfs1(x,y);
printf("%d step(s) before a loop of %d step(s)\n",counter-counter1,counter1);
}
else
{
printf("%d step(s) to exit\n",counter);
}
memset(color,false,sizeof color);
memset(str,'\0',sizeof str);
}
return 0;
}