#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
ld eps=1e-9;

vector<vector<int>>rotate_l(vector<vector<int>>vs) {
	vector<vector<int>>afvs(vs.size(),vector<int>(vs.size()));
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			afvs[2 - j][i] = vs[i][j];
		}
	}
	return afvs;
}
vector<vector<int>>rotate_r(vector<vector<int>>vs) {
	vs = rotate_l(vs);
	vs = rotate_l(vs);
	vs = rotate_l(vs);
	return vs;
}
vector<vector<int>>rotate_2(vector<vector<int>>vs) {
	vs = rotate_l(vs);
	vs = rotate_l(vs);
	return vs;
}

struct Dice {
	vector<vector<int>> tp;
	vector<vector<int>> bo;
	vector<vector<int>> no;
	vector<vector<int>> so;
	vector<vector<int>> ea;
	vector<vector<int>> we;
	Dice(vector<int>pips_) {

	}
	Dice():tp(3,vector<int>(3)),
		bo(3, vector<int>(3)),
		no(3, vector<int>(3)),
		so(3, vector<int>(3)),
		ea(3, vector<int>(3)),
		we(3, vector<int>(3))
	{
	}
	enum R_Way {
		R_Left,
		R_Front,
		R_Right,
		R_Back,

		R_Dummy,
	};
	bool check()const  {
		bool sook = false;
		bool nook = false;
		for (int i = 0; i < 3; ++i) {
			if (so[2][i])sook = true;
			if (no[2][i])nook = true;
		}
		return sook&&nook;
	}
	void rotate(const R_Way way) {
		switch (way) {
		case R_Right: {
			so = rotate_l(so);
			no = rotate_r(no);
			{
				vector<vector<int>>tmp = tp;
				tp = we;
				tp = rotate_l(tp);
				we = bo;
				we = rotate_l(we);
				bo = ea;
				bo = rotate_l(bo);
				ea = tmp;
				ea = rotate_l(ea);
			}
		}
					  break;
		case R_Back: {
			ea = rotate_l(ea);
			we = rotate_r(we);
			{
				vector<vector<int>>tmp = tp;
				tp = no;
				tp = rotate_2(tp);
				no = bo;
				no = rotate_2(no);
				bo = so;
				so = tmp;
			}
		}
					 break;
		case R_Left: {
			rotate(R_Right);
			rotate(R_Right);
			rotate(R_Right);
		}
					 break;
		case R_Front: {
			rotate(R_Back);
			rotate(R_Back);
			rotate(R_Back);
		}
					  break;
		default:
			assert(false);
		}
	}
	void rotate(const int way) {
		rotate(static_cast<R_Way>(way));
	}
	long long int hash()const {
		long long int hash = 0;
		long long int num = 1;
		for (int y = 0; y < 3; ++y) {
			for (int x = 0; x < 3; ++x) {
				if (tp[y][x])hash += num;
				num *= 2;
				if (bo[y][x])hash += num;
				num *= 2;
				if (no[y][x])hash += num;
				num *= 2;
				if (we[y][x])hash += num;
				num *= 2;
				if (so[y][x])hash += num;
				num *= 2;
				if (ea[y][x])hash += num;
				num *= 2;
			}
		}
		return hash;
	}
};
bool operator==(const Dice&l, const Dice&r) {
	return l.hash() == r.hash();
}
int geteast(int top, int south) {
	map<pair<int, int>, int>mp;
	mp[make_pair(1, 2)] = 3;
	mp[make_pair(1, 3)] = 5;
	mp[make_pair(2, 3)] = 1;
	mp[make_pair(2, 4)] = 6;
	bool rev = false;
	if (top >= 4) {
		rev = !rev; top = 7 - top;
	}
	if (south >= 4) {
		rev = !rev; south = 7 - south;
	}
	if (top > south) {
		rev = !rev; swap(top, south);
	}
	return mp[make_pair(top, south)];
}
int main() {
	while (1) {
		Dice di;
		for (int i = 0; i < 6; ++i) {
			vector<vector<int>>vs;
			for (int j = 0; j < 3; ++j) {
				vector<int>v(3);
				string st; cin >> st;
				if (st == "#")return 0;
				for (int k = 0; k < 3; ++k) {
					if (st[k] == '*')v[k] = 1;
				}
				vs.emplace_back(v);
			}
			switch (i) {
			case 0:
				di.so = vs;
				break;
			case 1:
				di.ea = vs;
				break;
			case 2:
				di.no = vs;
				break;
			case 3:
				di.we = vs;
				break;
			case 4:
				di.tp = vs;
				break;
			case 5:
				di.bo = vs;
				break;
			}
		}
		int ans = 9999;
		queue<pair<int, Dice>>que;
		map<long long int, int>mp;
		mp[di.hash()] = 0;
		que.push(make_pair(0, di));
		while (!que.empty()) {
			auto p = que.front();
			que.pop();
			const int nexttime = p.first + 1;
			const Dice ori = p.second;
			if (ori.check()) {
				ans = nexttime - 1;
				break;
			}
			for (size_t i = 0; i < 4; i++)
			{
				Dice now(ori);
				now.rotate(i);
				auto it = mp.find(now.hash());
				if (it == mp.end()) {
					mp[now.hash()] = nexttime;
					que.emplace(nexttime, now);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}