import math

def Readfile():
    for line in open("DATA4.txt","r"):
        for part in line.split():
            yield part
            
Next=Readfile().next

def Writeline(line):
    open("OUT4.txt","a").write(str(line)+"\n")
    
          
        
    
for element in range(5):
    forest=[list(("."*12))]
    count=0
    
    for x in xrange(10):
        line=Next()
        forest.append(["."]+list(line)+["."])
    forest.append(list(("."*12)))
    
    while True:
        lastf=[]
        for item in forest:
            row = []
            for thing in list(item):
                row.append(thing)
            lastf.append(row)
    
        for x in xrange(1,11):
            for y in xrange(1,11):
                
                if forest[x][y]=="F":
                    up=forest[x+1][y]
                    down=forest[x-1][y]
                    left=forest[x][y-1]
                    right=forest[x][y+1]
                    
                    if up=="T":
                        forest[x+1][y]="N"
                    if down=="T":
                        forest[x-1][y]="N"
                    if left=="T":
                        forest[x][y-1]="N"
                    if right=="T":
                        forest[x][y+1]="N"
        for x in xrange(1,11):
            for y in xrange(1,11):
                
                if forest[x][y]=="N":
                    forest[x][y]="F"

        if lastf==forest:
            break
        count+=1
    if count==0:
        Writeline(-1)
    else:
        Writeline(count)           
    
    #for item in forest:
        #print "".join(item)
        
    Next()

        
        
    
