3 dimensional Depth frist search
#include<stdio.h>
#include<queue>
#include<iostream>
#include<string.h>
using namespace std;
char s[10];
int f[20][20][20],p[20][20][20],x1,x2,y1,y2,z1,z2,i,j,n;
void dfs(int x,int y,int z,int w){
if(p[x][y][z]<=w)return;//Prune
if(!f[x][y][z])return;//Boundary condition
p[x][y][z]=w;//Update
dfs(x+1,y,z,w+1);
dfs(x,y+1,z,w+1);
dfs(x,y,z+1,w+1);
dfs(x-1,y,z,w+1);
dfs(x,y-1,z,w+1);
dfs(x,y,z-1,w+1);//Continue
}
int main(){
while(scanf("%s",s)!=EOF){
scanf("%d",&n);
getchar();
memset(f,0,sizeof(f));
for(i=1;i<=n;i++)
for(j=1;j<=n;j++,getchar())
for(int o=1;o<=n;o++)
if(getchar()=='O')f[o][j][i]=1;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
for(int o=1;o<=n;o++)
p[i][j][o]=0x3ffffff;//Init
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
x1++;
x2++;
y1++;
y2++;
z1++;
z2++;//Because first number if 0
scanf("%s",s);//Read "END"
dfs(x1,y1,z1,0);
if(p[x2][y2][z2]==0x3ffffff)puts("NO ROUTE");
else printf("%d %d\n",n,p[x2][y2][z2]);
}
return 0;
}