/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.*;
import java.util.*;
/**
 *
 * @author tangb6408
 */
public class Dwite4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        // TODO code application logic here
        Scanner sin = new Scanner(new FileReader("DATA4.txt"));
        PrintWriter fout = new PrintWriter(new FileWriter("OUT4.txt"));
        for(int test = 0; test < 5; test ++)
        {
            String forest[][] = new String[10][10];
            boolean fire[][] = new boolean[10][10];
            boolean spread = true;
            int counter = 0;
            for(int y = 0; y < 10; y ++)
            {
                String temp = sin.nextLine();
                for(int x = 0; x < 10; x ++)
                {
                    forest[x][y] = Character.toString(temp.charAt(x));
                }
            }
            while(spread == true)
            {
                spread = false;
                for(int y = 0; y < 10; y ++)
                {
                    for(int x = 0; x < 10; x ++)
                    {
                        if(forest[x][y].equals("F"))
                        {
                            fire[x][y] = true;
                        }
                    }
                }
                for(int y = 0; y < 10; y ++)
                {
                    for(int x = 0; x < 10; x ++)
                    {
                        if(fire[x][y] == true)
                        {
                            if(x + 1 < 10)
                            {
                                if(forest[x + 1][y].equals("T"))
                                {
                                    forest[x + 1][y] = "F";
                                    spread = true;
                                }
                            }
                            if(x - 1 >= 0)
                            {
                                if(forest[x - 1][y].equals("T"))
                                {
                                    forest[x - 1][y] = "F";
                                    spread = true;
                                }
                            }
                            if(y + 1 < 10)
                            {
                                if(forest[x][y + 1].equals("T"))
                                {
                                    forest[x][y + 1] = "F";
                                    spread = true;
                                }
                            }
                            if(y - 1 >= 0)
                            {
                                if(forest[x][y - 1].equals("T"))
                                {
                                    forest[x][y - 1] = "F";
                                    spread = true;
                                }
                            }
                        }
                    }
                }
                if(spread == true)
                {
                    counter ++;
                }
            }
            for(int y = 0; y < 10; y ++)
            {
                for(int x = 0; x < 10; x ++)
                {
                    if(forest[x][y].equals("T"))
                    {
                        spread = true;
                    }
                }
            }
            if(spread == false)
            {
                System.out.println(counter);
                fout.println(counter);
            }
            else
            {
                System.out.println("-1");
                fout.println("-1");
            }
            sin.nextLine();
        }
        sin.close();
        fout.close();
    }
}

