#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
//#define debug printf

char map[10][10];
char mapOld[10][10];
int counts;

bool allOnFire()
{
	for(int y = 0; y < 10; y++)
	{
		for(int x = 0; x < 10; x++)
		{
			if(map[y][x] == 'T')
				return false;
		}
	}
	return true;
}

void setFire(int x, int y)
{
	if(x >= 0 && x < 10
		&& y >= 0 && y < 10)
	{
		if(map[y][x] == 'T')
			map[y][x] = 'F';
	}
}
int main()
{
	freopen("DATA4.txt", "r", stdin);
	freopen("OUT4.txt", "w", stdout);

	for(int i0 = 0; i0 < 5; i0++)
	{
		for(int i = 0; i < 10; i++)
		{
			scanf("%s", &map[i]);
		}
		/*for(int y = 0; y < 10; y++)
		{
			for(int x = 0; x < 10; x++)
			{
				//debug("%c", map[y][x]);
			}
			//debug("\n");
		}*/
		memset(mapOld, 1, 100);
		int elapsed = 1;

		while(!allOnFire())
		{
			for(int y = 0; y < 10; y++)
			{
				for(int x = 0; x < 10; x++)
				{
					if(map[y][x] == 'F')
					{
						setFire(x+1, y);
						setFire(x-1, y);
						setFire(x, y+1);
						setFire(x, y-1);
					}
				}
			}
			//debug("frame %d:\n", elapsed);
			/*for(int y = 0; y < 10; y++)
			{
				for(int x = 0; x < 10; x++)
				{
					//debug("%c", map[y][x]);
				}
				//debug("\n");
			}*/
			if(!memcmp(map, mapOld, 100))
			{
				elapsed = -1;
				break;
			}
			
			memcpy(mapOld, map, 100);

			elapsed++;
		}
		printf("%d\n", elapsed);
		scanf("%s", map[0]);
	}
}
