天哪!!一个n写成m WA了我两天!!!!WA了我53次!!泪流满面啊!F****
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a) for( int i = (a)-1 ; i >= 0 ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define SZ(a) ((int)a.size())
#define PP(n,m,a) puts("---");FF(i,n){FF(j,m)cout << a[i][j] << ' ';puts("");}
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-10;
const double pi = acos(-1.0);
const int maxn = 102;
const int maxc = 42111;
const int mod = 1000000;
struct zz
{
int from;
int to;
}zx;
vector<zz>g[maxc];
char a[maxn][maxn];
int dp[maxc];
int way[maxc];
queue<int>q;
int sx,sy,sf;
int ex,ey;
int a1,a2;
int n,m;
inline bool yes(int x,int y)
{
if(x>=0 && x<n && y>=0 && y<m)
{
return true;
}
return false;
}
inline int num(int f,int x,int y)
{
return (x*m+y)*4+f;
}
inline int dx(int temp)
{
temp/=4;
return temp/m;
}
inline int dy(int temp)
{
temp/=4;
return temp%m;
}
void bfs()
{
CL(q);
int st = num(sf,sx,sy);
q.push(st);
way[st] = 0;
dp[st] = 1;
int now,to;
while(!q.empty())
{
now = q.front();
q.pop();
for(int i=0;i<g[now].size();i++)
{
to = g[now][i].to;
if(way[to]==-1)
{
way[to] = way[now] + 1;
dp[to] += dp[now];
dp[to]%=mod;
q.push(to);
}
else if(way[to] == way[now]+1)
{
dp[to] += dp[now];
dp[to] %= mod;
}
}
}
int temp = inf;
for(int u=0;u<4;u++)
{
if(way[num(u,ex,ey)] < temp)
{
temp = way[num(u,ex,ey)];
}
}
if(temp == -1)
{
a1 = 0;
a2 = 0;
return ;
}
int ans = 0;
for(int u=0;u<4;u++)
{
if(temp == way[num(u,ex,ey)] )
{
ans += dp[num(u,ex,ey)];
}
}
ans %= mod;
a1 = temp;
a2 = ans;
return ;
}
void start()
{
for(int i=0;i<maxc;i++)
{
dp[i] = 0;
way[i] = -1;
}
bfs();
return ;
}
void init()
{
for(int i=0;i<maxc;i++)
{
g[i].clear();
}
int now,to;
int cost;
int tox,toy;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]=='*') continue;
for(int f=0;f<4;f++)
{
now = num(f,i,j);
for(int u=0;u<4;u++)
{
cost = abs(u - f)%2;
if(cost!=1) continue;
to = num(u,i,j);
zx.to = to;
zx.from = now;
g[now].pb(zx);
}
if(f==2)
{
for(int x=1;x<=n;x++)
{
tox = i+x;
toy = j;
if(yes(tox,toy))
{
if(a[tox][toy]=='*') break;
to = num(f,tox,toy);
zx.from = now;
zx.to = to;
g[now].pb(zx);
}
else
{
break;
}
}
}
else if(f==0)
{
for(int x=1;x<=n;x++)
{
tox = i - x;
toy = j;
if(yes(tox,toy))
{
if(a[tox][toy]=='*') break;
to = num(f,tox,toy);
zx.from = now;
zx.to = to;
g[now].pb(zx);
}
else
{
break;
}
}
}
else if(f==1)
{
for(int y=1;y<=m;y++)
{
tox = i;
toy = j + y;
if(yes(tox,toy))
{
if(a[tox][toy]=='*') break;
to = num(f,tox,toy);
zx.from = now;
zx.to = to;
g[now].pb(zx);
}
else
{
break;
}
}
}
else if(f==3)
{
for(int y=1;y<=m;y++)
{
tox = i;
toy = j - y;
if(yes(tox,toy))
{
if(a[tox][toy]=='*') break;
to = num(f,tox,toy);
zx.from = now;
zx.to = to;
g[now].pb(zx);
}
else
{
break;
}
}
}
}
}
}
return ;
}
int main()
{
// read;
// write;
while(cin>>n>>m)
{
if(n==0 && m==0) break;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>a[i][j];
if(a[i][j]=='N'||a[i][j]=='E'||a[i][j]=='W'||a[i][j]=='S')
{
sx = i;
sy = j;
if(a[i][j]=='N') sf = 0;
if(a[i][j]=='E') sf = 1;
if(a[i][j]=='S') sf = 2;
if(a[i][j]=='W') sf = 3;
}
if(a[i][j]=='X')
{
ex = i;
ey = j;
}
}
}
init();
start();
cout<<a1<<" "<<a2<<endl;
}
return 0;
}