#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>

using namespace std;

int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};

vector<string> move(vector<string> s, char k, int p, int move)
{
	int cnt = 0;
	for (int i = 0;i < 3;i++)
		for (int j = 0;j < 3;j++)
			if (s[i][j] == k)
			{
				if (p == cnt)
				{
					int nx, ny;
					nx = i + dx[move];
					ny = j + dy[move];
					if (nx < 0 || ny < 0 || nx >= 3 || ny >= 3 || s[nx][ny] != '.')
						return vector<string>();

					s[nx][ny] = s[i][j];
					s[i][j] = '.';
					return s;
				}
				cnt++;
			}
	return s;
}

int res(vector<string> &start, vector<string> &end)
{
	map<vector<string>, int > dist;
	set<vector<string> > vis;
	dist[start] = 0;
	queue<vector<string> > q;
	q.push(start);

	while (!q.empty())
	{
		vector<string> v = q.front();
		q.pop();
		int dv = dist[v];
		char buf[] = "WB";
		for (int i = 0;i < 2;i++)
			for (int j = 0;j < 2;j++)
				for (int k = 0;k < 8;k++)
				{
					vector<string> nv = move(v, buf[i], j, k);
					if (nv.size() == 0)
						continue;
					if (vis.count(nv) == 0)
					{
						dist[nv] = dv + 1;
						vis.insert(nv);
						q.push(nv);
					}
				}
	}

	map<vector<string>, int >::iterator ans = dist.find(end);
	return ans == dist.end() ? -1 : ans->second;
}

int main()
{
	ifstream in("chess.in");

	int tc;
	in >>tc;
	while (tc--)
	{
		vector<string> s, f;
		for (int i = 0;i < 6;i++)
		{
			string str;
			in >>str;
			if (i % 2 == 0)
				s.push_back(str);
			else
				f.push_back(str);
		}

		cout <<res(s, f) <<endl;
	}

	return 0;
}