#include <iostream>
#include <fstream>

using namespace std;

char map[10][10]; // x y
char map2[10][10]; // x y

bool good (int x, int y) {
  return (x>=0 && x<10 && y>=0 && y<10);
}

void setfire (int x,int y) {
  if (good(x,y) && map[x][y]=='T') // was a tree
    map2[x][y]='F'; // on fire now
}

int main() {
  ifstream fin ("DATA4.txt");
  ofstream fout ("OUT4.txt");

  for (int set=0;set<5;set++) {
    int ntree=1,T=0;

    for (int y=0;y<10;y++)
      for (int x=0;x<10;x++)
        fin>>map[x][y];

    for (T=0;T<100 && ntree;T++) {
      ntree=0;
      for (int y=0;y<10;y++)
        for (int x=0;x<10;x++)
          map2[x][y]=map[x][y];
      for (int y=0;y<10;y++)
        for (int x=0;x<10;x++)
          if (map[x][y]=='F') {
            setfire (x-1,y);
            setfire (x+1,y);
            setfire (x,y-1);
            setfire (x,y+1);
          } else if (map[x][y]=='T') {
            ntree++;
          }
      for (int y=0;y<10;y++) {
        for (int x=0;x<10;x++) {
          //cout << map[x][y];
          map[x][y]=map2[x][y];
        }
        //cout << endl;
      }
      //cout << ntree;
      if (ntree==0) break;
    }
    if (ntree>0) fout << "-1" << endl;
    else fout << T << endl;

    char bad[100]; fin >> bad;
  }
}

