data = open("DATA4.txt","r")
out = open("OUT4.txt","w")

move = [[1,0],[0,1],[-1,0],[0,-1]]

for p in range(5):
    g =[]
    for i in range(10):
        x = [s for s in data.readline().strip()]
        g.append(x)
    count = -1
    flag = True

    while flag:
        k = 0
        flag = False
        temp = []
        for i in g:
            temp.append([j for j in i])
        for i in range(10):
            for j in range(10):
                if g[i][j]=="F":
                    for l in range(4):
                        if 0<=i+move[l][0]<10 and 0<=j+move[l][1]<10:
                            if g[i+move[l][0]][j+move[l][1]]=="T":
                                temp[i+move[l][0]][j+move[l][1]]="F"
                                flag = True
        count +=1
        g = temp[:]
        #print count
        #print g
    pout = True
    dotflag = True
    for i in range(10):
        for j in range(10):
            if g[i][j]=="T":
                pout = False
            if g[i][j]!=".":
                dotflag = False
    if pout and not dotflag:
        print count
        out.write(str(count)+"\n")
    else:
        print -1
        out.write("-1\n")
    
    data.readline()

        
        
out.close()

