import java.io.*;
import java.util.*;

public class P4
{
	public static void main( String[] args ) throws Exception
	{
		Scanner in = new Scanner( new FileReader( "DATA4.txt" ) );
		PrintWriter out = new PrintWriter( new FileWriter( "OUT4.txt" ) );
		
		for( int i = 0; i < 5; i++ )
		{
			char[][] map = new char[10][10];
			for( int j = 0; j < 10; j++ )
			{
				map[j] = in.next().toCharArray();
			}
			
			int move = 0;
			boolean fire = true;
			do
			{
				fire = false;
				
				for( int r = 0; r < 10; r++ )
				{
					for( int c = 0; c < 10; c++ )
					{
						if( map[r][c] == 'F' )
						{
							int[] dx = { 0, 1, 0, -1 };
							int[] dy = { -1, 0, 1, 0 };
							for( int k = 0; k < 4; k++ )
							{
								if( r + dy[k] >= 0 && r + dy[k] < 10 && c + dx[k] >= 0 && c + dx[k] < 10 )
								{
									if( map[r+dy[k]][c+dx[k]] == 'T' )
									{
										map[r+dy[k]][c+dx[k]] = 'f';
										fire = true;
									}
								}
							}
						}
					}
				}
				
				for( int r = 0; r < 10; r++ )
				{
					for( int c = 0; c < 10; c++ )
					{
						if( map[r][c] == 'f' )
						{
							map[r][c] = 'F';
						}
						else if( map[r][c] == 'F' )
						{
							map[r][c] = '.';
						}
					}
				}
				
				move++;
			} while( fire );
			
			boolean isTrees = false;
			for( int r = 0; r < 10; r++ )
			{
				for( int c = 0; c < 10; c++ )
				{
					if( map[r][c] == 'T' )
					{
						isTrees = true;
					}
				}
			}
			
			if( !isTrees )
				out.println( move - 1 );
			else
				out.println( -1 );
			
			String s = in.next();
		}
		
		in.close();
		out.close();
	}
}
