import java.util.Vector;
import java.util.Iterator;
import java.util.Scanner;
import java.io.File;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.awt.Point;


public class q4
{

    public static void main(String[] args){
        Vector inFileBuffer = new Vector();
        Vector outFileBuffer = new Vector();
        if(!loadFile("DATA4.txt",inFileBuffer))
            System.err.println("Fail to laod the specific file...");
        //Main program goes here
        
        for (int asd=0;asd<2;asd++){
            Vector nodeBuffer = new Vector();
            for (int i=0;i<10;i++){
                String s = (String)inFileBuffer.get(i+asd*10);
                for (int i2=0;i2<10;i2++)
                    if (s.charAt(i2)=='#') nodeBuffer.add(new Point(i2,i));
            }
            if (nodeBuffer.size()==2){
                Point p1=(Point)nodeBuffer.get(0),p2=(Point)nodeBuffer.get(1);
                int num = Math.abs(p1.x-p2.x+p1.y-p2.y)*2;
                outFileBuffer.add(""+num);
            }else{
                Vector pairList = new Vector();
                for (Iterator i=nodeBuffer.iterator();i.hasNext();){
                    Point tempP1 = (Point)i.next();
                    for (Iterator i2=nodeBuffer.iterator();i2.hasNext();){
                        Point tempP2 = (Point)i2.next();
                        pairList.add(new Pair(tempP1,tempP2));
                    }
                }
                for (int i = 0;i<pairList.size();i++)
                    for (int i2 = pairList.size()-1;i2>i;i2--){
                        Pair p1 =(Pair)pairList.get(i2),p2 = (Pair)pairList.get(i2-1);
                        if (p1.dis()<p2.dis()){
                            Pair temp = (Pair)pairList.get(i2);
                            pairList.remove(i2);
                            pairList.add(i2,pairList.get(i2-1));
                            pairList.remove(i2-1);
                            pairList.add(i2-1,temp);
                        }}
                Vector doneList = new Vector();
                int iNum = 0,iCount = 0;
                for (Iterator i = pairList.iterator();i.hasNext();){
                    boolean b = true;
                    int inum = 0;
                    Pair pair = (Pair)i.next();
                    for (Iterator i2 = doneList.iterator();i2.hasNext();){
                        Pair tPair = (Pair)i2.next();
                        if (pair.check(tPair)) inum++;
                        b = pair.checkBoth(tPair) && (inum < 2);
                    }
                    if (b){ iNum=iNum + pair.dis();
                        doneList.add(pair);
                    }
                }
                outFileBuffer.add(""+iNum);
            }
            
        }
        //end of Main program
        if(!writeFile("OUT4.txt",outFileBuffer))
            System.err.println("Fail to write the specific file...");
    }
//===---===---===---===---===---===---===---===---===---===---===---===
//===---===---===-I am methods and main seperation line-===---===---===
//===---===---===---===---===---===---===---===---===---===---===---===
    private static class Pair{
        public Point p1,p2;
        public Pair(Point pp1,Point pp2){
            p1 = pp1;
            p2 = pp2;
        }
        public int dis(){
            int num = Math.abs(p1.x-p2.x)+Math.abs(p1.y-p2.y);            
            return num;
        }
        public boolean check(Pair p){
            return !(p1.hashCode()==p.p1.hashCode() || p2.hashCode()==p.p2.hashCode());
        }
        public boolean checkBoth(Pair p){
            return !(p1.hashCode()==p.p2.hashCode() && p2.hashCode()==p.p1.hashCode());
        }
    }

    private static boolean loadFile(String s,Vector v){
        try{
            Scanner fileIn = new Scanner(new File(s));
            for (Scanner sca = fileIn; sca.hasNext();){
                v.add(sca.nextLine());
            }
            fileIn.close();
            return true;
        }
        catch(Exception e){
            return false;
        }
    }
    
    private static boolean writeFile(String s,Vector v){
        try{
            PrintStream fileOut = new PrintStream(new FileOutputStream(s));
            for(Iterator i = v.iterator();i.hasNext();){
                String temp = (String)i.next();
                fileOut.println(temp);
            }
            fileOut.close();
            return true;
        }
        catch(Exception e){
            return false;
        }
    }

}

