#!/usr/bin/env python
import sys
sys.stdin = open('DATA4.txt')
sys.stdout = open('OUT4.txt', 'w')

def step(forest):
    hasfire = False
    delta = ((1,0), (-1,0), (0,1), (0,-1))
    for y in range(10):
        for x in range(10):
            if forest[y][x] == 'F':
                hasfire = True
                for dx,dy in delta:
                    if (0 <= x+dx < 10 and 0 <= y+dy < 10 and 
                       forest[y+dy][x+dx] == 'T'):
                        forest[y+dy][x+dx] = 'f'
                forest[y][x] = '.'
    for y in range(10):
        for x in range(10):
            if forest[y][x] == 'f':
                forest[y][x] = 'F'
    return hasfire

for _ in range(5):
    forest = [list(input().strip()) for _ in range(10)]
    input()
    steps = -1
    while step(forest):
        #print(forest)
        steps += 1
    if ''.join(map(str,forest)).count('.') < 100:
        print(-1)
    else:
        print(steps)

