#include <bits/stdc++.h>
using namespace std;
string s[10];
int t, x, y, p, q;
int main()
{
    freopen(".1.in","r",stdin);
    freopen(".1.out","w",stdout);
    cin>>t;
    while( t-- )
    {
        int cnt = 0, ans = 987654321, b[3] = {0, 1, 2};
        for(int i = 0 ; i < 8 ; i++ )
        {
            cin>>s[i];
            for(int j = 0 ; j < 8 ; j++ )
                if( s[i][j] == 'B' ) x = i, y = j;
                else if( s[i][j] == 'T' ) p = i, q = j;
        }
        if( (x+y)%2 == (p+q)%2 )
        {
            if( (x+y) == (p+q) ) cout<<1<<endl;
            else if( x-y == p-q ) cout<<1<<endl;
            else cout<<2<<endl;
        }
        else cout<<"-1\n";
    }
}

