#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

int count = 0; // init
int repeat = 0;
char forest[11][10];

bool CheckTree() {
	for(int a=0; a<=9; a++)
		for(int b=0; b<=9; b++)
			if(forest[a][b] == 'T') return true;
	return false;
}

void TempFire() {
	for(int a=0; a<=9; a++)
		for(int b=0; b<=9; b++)
			if(forest[a][b] == '*') forest[a][b] = 'F';
}

void main() {
	ifstream ifile;
	ofstream ofile;
	ofile.open("OUT4.txt",ios_base::out);
	ifile.open("DATA4.txt",ios_base::in);
	for(int i=0; i<=4; i++) {
		count = 0; // init
		repeat = 0; // init
		for(int i=0; i<=10; i++) ifile>>forest[i];
		while(CheckTree() == true) {
			repeat++;
			if(repeat >= 50) {
				ofile<<"-1\n";
				break;
			}
			for(int l=0; l<=9; l++) {
				for(int w=0; w<=9; w++) {
					if(forest[l][w] == 'F') {
						if(forest[l-1][w] == 'T') forest[l-1][w] = '*';
						if(forest[l+1][w] == 'T') forest[l+1][w] = '*';
						if(forest[l][w-1] == 'T') forest[l][w-1] = '*';
						if(forest[l][w+1] == 'T') forest[l][w+1] = '*';
					}
				}
			}
			count++;
			TempFire();
		}
		if(CheckTree() == false) ofile<<count<<"\n";
	}
}
