#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

enum Men{
	Syoumen,
	Migi,
	Haimen,
	Hidari,
	Ue,
	Shita,
};

Men men_array[6] = {Syoumen,Migi,Haimen,Hidari,Ue,Shita};

enum Loc{
	Top,
	Right,
	Left,
	Bottom,
};

char buf[4];

void func(){

	bool table[6][4];
	for(int i = 0; i < 6; i++){
		for(int k = 0; k < 4; k++){
			table[i][k] = false;
		}
	}

	for(int col = 0; col < 3; col++){
		if(buf[col] == '*'){
			table[Syoumen][Top] = true;
			if(col == 0){
				table[Syoumen][Left] = true;
			}
			if(col == 2){
				table[Syoumen][Right] = true;
			}
		}
	}

	scanf("%s",buf);
	for(int col = 0; col < 3; col++){
		if(buf[col] == '*'){
			if(col == 0){
				table[Syoumen][Left] = true;
			}
			if(col == 2){
				table[Syoumen][Right] = true;
			}
		}
	}

	scanf("%s",buf);
	for(int col = 0; col < 3; col++){
		if(buf[col] == '*'){
			table[Syoumen][Bottom] = true;
			if(col == 0){
				table[Syoumen][Left] = true;
			}
			if(col == 2){
				table[Syoumen][Right] = true;
			}
		}
	}

	for(int i = 1; i <= 5; i++){

		scanf("%s",buf);
		for(int col = 0; col < 3; col++){
			if(buf[col] == '*'){
				table[men_array[i]][Top] = true;
				if(col == 0){
					table[men_array[i]][Left] = true;
				}
				if(col == 2){
					table[men_array[i]][Right] = true;
				}
			}
		}

		scanf("%s",buf);
		for(int col = 0; col < 3; col++){
			if(buf[col] == '*'){
				if(col == 0){
					table[men_array[i]][Left] = true;
				}
				if(col == 2){
					table[men_array[i]][Right] = true;
				}
			}
		}

		scanf("%s",buf);
		for(int col = 0; col < 3; col++){
			if(buf[col] == '*'){
				table[men_array[i]][Bottom] = true;
				if(col == 0){
					table[men_array[i]][Left] = true;
				}
				if(col == 2){
					table[men_array[i]][Right] = true;
				}
			}
		}
	}

	int ans = BIG_NUM;

	//{Syoumen,Migi,Haimen,Hidari,Ue,Shita};

	if(table[Syoumen][Bottom] == true && table[Haimen][Bottom] == true){
		ans = 0;
	}

	if((table[Syoumen][Right] == true && table[Haimen][Left] == true) || (table[Syoumen][Left] == true && table[Haimen][Right] == true)){
		ans = min(ans,1);
	}

	if(table[Syoumen][Top] == true && table[Haimen][Top] == true){
		ans = min(ans,2);
	}

	if((table[Ue][Bottom] == true && table[Shita][Top] == true) || (table[Ue][Top] == true && table[Shita][Bottom] == true)){
		ans = min(ans,1);
	}

	if((table[Ue][Right] == true && table[Shita][Right] == true) || (table[Ue][Left] == true && table[Shita][Left] == true)){
		ans = min(ans,2);
	}

	if((table[Migi][Left] == true && table[Hidari][Right] == true) || (table[Migi][Right] == true && table[Hidari][Left] == true)){
		ans = min(ans,2);
	}

	if((table[Migi][Top] == true && table[Hidari][Top] == true) || (table[Migi][Bottom] == true && table[Hidari][Bottom] == true)){
		ans = min(ans,3);
	}

	printf("%d\n",ans);

}

int main(){

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		func();
	}


}