#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
int d[4] = {-1, 1, 0, 0};
main(){
    ifstream in("DATA4.txt");
    ofstream out("OUT4.txt");
    for (int z = 5; z--; )
    {
        int a[10][10];
        for (int i = 0; i < 10; i++)
        {
            string inp;
            in >> inp;
            for (int j = 0; j < 10; j++)
                a[i][j] = inp[j];
        }
        bool change = true;
        int t = 0;
        while (change)
        {
            /*for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                    cout << char(a[i][j]);
                cout << endl;
            }*/
            int a2[10][10];
            memcpy(a2, a, 100*sizeof(int));
            change = false;
            for (int i = 0; i < 10; i++)
                for (int j = 0; j < 10; j++)
                    if (a2[i][j]=='F')
                        for (int k = 0; k < 4; k++)
                        {
                            int x = i+d[k];
                            int y = j+d[(k+2)%4];
                            if (x < 0 || x >= 10)
                                continue;
                            if (y < 0 || y >= 10)
                                continue;
                            if (a2[x][y] == 'T')
                            {
                                change = true;
                                a[x][y] = 'F';
                            }
                        }
            if (change)
                t++;
        }
        bool alldead = true;
        for (int i = 0; i < 10; i++)
            for (int j = 0; j < 10; j++)
                if (a[i][j] == 'T')
                    alldead = false;
        //cout << t << endl;
        //while (true);
        if (!alldead)
            out << -1 << endl;
        else
            out << t << endl;
        string blah;
        in >> blah;
    }
}

