#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

bool input(vs& v)
{
	v.resize(18);
	REP(i, 18)
	{
		cin >> v[i];
		if (v[i] == "#") return false;
	}
	return true;
}

vs to_clock(vs& v)
{
	vs res(3, string("@@@"));
	REP(i, 3)REP(j,3)res[i][j] = v[2-j][i];
	return res;
}

vs to_cclock(vs& v)
{
	vs res = v;
	REP(i, 3) res = to_clock(res);
	return res;
}

vs reverse(vs& v)
{
	vs res = v;
	REP(i, 3)REP(j, 3) res[i][j] = v[2 - i][2 - j];
	return res;
}

struct Room
{
	vs front, right, back, left, top, bottom;
	Room(vs v)
	{
		FOR(i, 0, 3) front.push_back(v[i]);
		FOR(i, 3, 6) right.push_back(v[i]);
		FOR(i, 6, 9) back.push_back(v[i]);
		FOR(i, 9, 12) left.push_back(v[i]);
		FOR(i, 12, 15) top.push_back(v[i]);
		FOR(i, 15, 18) bottom.push_back(v[i]);
	}
	void to_front()
	{
		vs nfront, nright, nback, nleft, ntop, nbottom;
		nfront = bottom;
		ntop = front;
		nback = reverse(top);
		nbottom = reverse(back);
		nleft = to_cclock(left);
		nright = to_clock(right);
		front = nfront;
		right = nright;
		back = nback;
		left = nleft;
		top = ntop;
		bottom = nbottom;
	}
	void to_back() 
	{
		REP(i, 3) to_front();
	}
	void to_right()
	{
		vs nfront, nright, nback, nleft, ntop, nbottom;
		ntop = to_clock(left);
		nleft = to_clock(bottom);
		nbottom = to_clock(right);
		nright = to_clock(top);
		nfront = to_clock(front);
		nback = to_cclock(back);
		front = nfront;
		right = nright;
		back = nback;
		left = nleft;
		top = ntop;
		bottom = nbottom;
	}
	void to_left()
	{
		REP(i, 3) to_right();
	}
};

bool check(Room& room)
{
	vs a = room.front, b = room.back;
	bool f1 = false, f2 = false;
	REP(i, 3)
	{
		if (a[2][i] == '*') f1 = true;
		if (b[2][i] == '*') f2 = true;
	}
	return f1 && f2;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	vs v;
	while (input(v))
	{
		Room room(v);
		queue<pair<Room, int>> que;
		que.emplace(room, 0);
		while (!que.empty())
		{
			Room tmp = que.front().first; int t = que.front().second;
			que.pop();
			if (check(tmp))
			{
				cout << t << endl;
				break;
			}
			Room nx = tmp;
			nx.to_front();
			que.emplace(nx, t + 1);
			nx = tmp;
			nx.to_back();
			que.emplace(nx, t + 1);
			nx = tmp;
			nx.to_right();
			que.emplace(nx, t + 1);
			nx = tmp;
			nx.to_left();
			que.emplace(nx, t + 1);
		}
		
	}
	return 0;
}