// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
vector<vs>in(6,vs(3));
int main(){
	while(1){
		string t;cin>>t;
		if(t=="#")return 0;
		rep(i,6)rep(j,3){
			if(i+j==0)in[i][j]=t;
			else cin>>in[i][j];
		}
		rep(i,3){
			reverse(all(in[2][i]));
			reverse(all(in[3][i]));
		}
		rep(i,3)
			swap(in[5][0][i],in[5][2][i]);

		int out=inf;
		if((in[0][0][0]=='*'||in[0][0][1]=='*'||in[0][0][2]=='*')&&
		   (in[2][0][0]=='*'||in[2][0][1]=='*'||in[2][0][2]=='*'))out=min(out,2);
		if((in[0][2][0]=='*'||in[0][2][1]=='*'||in[0][2][2]=='*')&&
		   (in[2][2][0]=='*'||in[2][2][1]=='*'||in[2][2][2]=='*'))out=min(out,0);
		if((in[0][0][0]=='*'||in[0][1][0]=='*'||in[0][2][0]=='*')&&
		   (in[2][0][0]=='*'||in[2][1][0]=='*'||in[2][2][0]=='*'))out=min(out,1);
		if((in[0][0][2]=='*'||in[0][1][2]=='*'||in[0][2][2]=='*')&&
		   (in[2][0][2]=='*'||in[2][1][2]=='*'||in[2][2][2]=='*'))out=min(out,1);

		if((in[1][0][0]=='*'||in[1][0][1]=='*'||in[1][0][2]=='*')&&
		   (in[3][0][0]=='*'||in[3][0][1]=='*'||in[3][0][2]=='*'))out=min(out,3);
		if((in[1][2][0]=='*'||in[1][2][1]=='*'||in[1][2][2]=='*')&&
		   (in[3][2][0]=='*'||in[3][2][1]=='*'||in[3][2][2]=='*'))out=min(out,3);
		if((in[1][0][0]=='*'||in[1][1][0]=='*'||in[1][2][0]=='*')&&
		   (in[3][0][0]=='*'||in[3][1][0]=='*'||in[3][2][0]=='*'))out=min(out,2);
		if((in[1][0][2]=='*'||in[1][1][2]=='*'||in[1][2][2]=='*')&&
		   (in[3][0][2]=='*'||in[3][1][2]=='*'||in[3][2][2]=='*'))out=min(out,2);

		if((in[4][0][0]=='*'||in[4][0][1]=='*'||in[4][0][2]=='*')&&
		   (in[5][0][0]=='*'||in[5][0][1]=='*'||in[5][0][2]=='*'))out=min(out,1);
		if((in[4][2][0]=='*'||in[4][2][1]=='*'||in[4][2][2]=='*')&&
		   (in[5][2][0]=='*'||in[5][2][1]=='*'||in[5][2][2]=='*'))out=min(out,1);
		if((in[4][0][0]=='*'||in[4][1][0]=='*'||in[4][2][0]=='*')&&
		   (in[5][0][0]=='*'||in[5][1][0]=='*'||in[5][2][0]=='*'))out=min(out,2);
		if((in[4][0][2]=='*'||in[4][1][2]=='*'||in[4][2][2]=='*')&&
		   (in[5][0][2]=='*'||in[5][1][2]=='*'||in[5][2][2]=='*'))out=min(out,2);
		cout<<out<<endl;
	}
}







Measured memory_bytes: 3164