#include<cstdio>
#include<cmath>
#include<cctype>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int L = 8*9*5*7;
bool full[5][5][5];
#define rep(i,a,b) for(int i=a;i<=b;++i)
vector<int> pos;
map<ll,int> idmap;
vector<pair<int,double> >e[10000];
double d[10000];
bool w[10000];
int id(int x,int y,int z){
	ll a = (ll)x<<40 | (ll)y<<20 |z;
	map<ll,int> :: iterator it = idmap.find(a);
	if(it!=idmap.end())return it->second;
	int b=idmap.size();
	return idmap[a]=b;
}
inline int sqr(int x){return x*x;}
void ae(int x,int y,int z,int a,int b,int c){
	double dis = sqrt(sqr(x-a)+sqr(y-b)+sqr(z-c));
	int p= id(x,y,z),q=id(a,b,c);
	e[p].push_back({q,dis});
	e[q].push_back({p,dis});
}
int main(){
	{	set<int> pos;
		for(int i=2;i<=9;++i)
		for(int j=0;j<=i;++j)
			pos.insert(L/i*j);
		::pos.assign(pos.begin(),pos.end());
	}
	for(int ax,ay,az,bx,by,bz;scanf("%d%d%d%d%d%d",&ax,&ay,&az,&bx,&by,&bz),
		ax||ay||az||bx||by||bz;){
		rep(z,1,3)rep(y,1,3)rep(x,1,3){
			static char c;
			while(isspace(c=getchar()));
			full[x][y][z]=(c=='#');
		}
		idmap.clear();
		rep(x,0,3)rep(y,0,3)rep(z,0,3){
			int X=x*L,Y=y*L,Z=z*L;
			if(y && z && (full[x][y][z]^full[x+1][y][z])){
				for(int a:pos)for(int b:pos){
					ae(X,Y-a,Z  ,X,Y-b,Z-L);
					ae(X,Y  ,Z-a,X,Y-L,Z-b);
					ae(X,Y-a,Z  ,X,Y  ,Z-b);
					ae(X,Y-a,Z-L,X,Y  ,Z-b);
					ae(X,Y-a,Z  ,X,Y-L,Z-b);
					ae(X,Y-a,Z-L,X,Y-L,Z-b);
				}
			}
			if(z && x && (full[x][y][z]^full[x][y+1][z])){
				for(int a:pos)for(int b:pos){
					ae(X-a,Y,Z  ,X-b,Y,Z-L);
					ae(X  ,Y,Z-a,X-L,Y,Z-b);
					ae(X-a,Y,Z  ,X  ,Y,Z-b);
					ae(X-a,Y,Z-L,X  ,Y,Z-b);
					ae(X-a,Y,Z  ,X-L,Y,Z-b);
					ae(X-a,Y,Z-L,X-L,Y,Z-b);
				}
			}
			if(x && y && (full[x][y][z]^full[x][y][z+1])){
				for(int a:pos)for(int b:pos){
					ae(X-a,Y  ,Z,X-b,Y-L,Z);
					ae(X  ,Y-a,Z,X-L,Y-b,Z);
					ae(X-a,Y  ,Z,X  ,Y-b,Z);
					ae(X-a,Y-L,Z,X  ,Y-b,Z);
					ae(X-a,Y  ,Z,X-L,Y-b,Z);
					ae(X-a,Y-L,Z,X-L,Y-b,Z);
				}
			}
		}
		int s = id(ax*L,ay*L,az*L),t=id(bx*L,by*L,bz*L);
		queue<int> q;
		fill(d,d+idmap.size(),1e99);
		fill(w,w+idmap.size(),false);
		d[s] = 0;w[s]=1;q.push(s);
		for(int u,v;q.size();q.pop(),w[u]=0){
			u=q.front();
			for(auto t:e[u])
			  if(d[v = t.first]>d[u]+t.second){
				d[v]=d[u]+t.second;
				if(!w[v]){
				  w[v]=1;
				  q.push(v);
				}
			  }
		}
		//printf("%d  ",idmap.size());
		printf("%lf\n",d[t]/L);
		for(int i=idmap.size();i;)e[--i].clear();
	}
}