import java.io.*;
import java.util.*;

public class D4 {
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(new BufferedReader(new FileReader("Data4.txt")));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(
				"Out4.txt")));
		for (int i = 0; i < 5; i++) {
			int time = 0;
			int numTrees = 0;
			char[][] a = new char[10][10];
			for (int j = 0; j < 10; j++) {
				String line = s.nextLine();
				for (int k = 0; k < 10; k++) {
					a[j][k] = line.charAt(k);
					if (a[j][k] == 'T') {
						numTrees++;
					}
				}
			}

			while (numTrees != 0) {
				int pastTrees = numTrees;
				for (int x = 0; x < 10; x++) {
					for (int y = 0; y < 10; y++) {
						if (a[x][y] == 'F') {

							try {
								if (a[x - 1][y] == 'T') {
									a[x - 1][y] = 'S';
									numTrees--;
								}
							} catch (Exception e) {
							}
							try {
								if (a[x + 1][y] == 'T') {
									a[x + 1][y] = 'S';
									numTrees--;
								}
							} catch (Exception e) {
							}
							try {
								if (a[x][y - 1] == 'T') {
									a[x][y - 1] = 'S';
									numTrees--;
								}
							} catch (Exception e) {
							}
							try {
								if (a[x][y + 1] == 'T') {
									a[x][y + 1] = 'S';
									numTrees--;
								}
							} catch (Exception e) {
							}
						}
					}
				}
				time++;
				for (int x = 0; x < 10; x++) {
					for (int y = 0; y < 10; y++) {
						if (a[x][y] == 'S') {
							a[x][y] = 'F';
						}
					}
				}
				if (pastTrees == numTrees) {
					pw.println(-1);
					numTrees = -1;
					break;
				}
			}
			if (numTrees == 0) {
				pw.println(time);
			}
			s.nextLine();
		}
		pw.close();

	}
}

