#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <cstdlib>


#define BIG 999999

using namespace std;

struct Coord{
    int x, y;
    Coord (int a, int b){
        x = a;
        y = b;
    }
};

char grid[10][10];
bool gchecked[10][10];
int shortest = BIG;
int dir[8][2] = {{-1, -1}, {-1,0 }, {-1,1 }, {0,-1 }, {0,1 }, {1,-1 }, {1,0 }, {1,1 }};
int dist[10][10];
queue <Coord> toCheck;

bool checkBounds(int x, int y){
    return (x >= 0 && x <10 && y >= 0 && y < 10);
}

void resetDist(){
    for (int i = 0; i < 10; ++i){
        for (int j = 0; j < 10; ++j){
            dist[i][j] = -1;
        }
    }
}

void findShortest(Coord cell){
    do {
        if (!toCheck.empty()){
            cell = toCheck.front();
            toCheck.pop();
        }
        for (int i = 0; i < 8; ++i){
            Coord next(cell.x + dir[i][0], cell.y + dir[i][1]);
            if (checkBounds(next.x, next.y)){
                if (dist[next.x][next.y] == -1 && grid[next.x][next.y] != '#'){
                    dist[next.x][next.y] = dist[cell.x][cell.y] + 1;
                    toCheck.push(next);
                }
            }
        }
    } while (!toCheck.empty());
}





int main()
{
    ofstream fout   ("Out4.txt");
    ifstream fin    ("Data4.txt");
    int i, j, k;
    char info;
    int x[2], y[2];
    int count = 0;
    bool end = false;
    
for (int k = 0; k < 5; ++k){

    count = 0;
    for (int i = 0; i < 10; ++i){
        for (int j = 0; j < 10; ++j){
            fin >> grid[j][i];        
        }
    }
        
    for (int i = 0; i < 10; ++i){
        for (int j = 0; j < 10; ++ j){
            if (grid[j][i] == 'X'){
                x[count] = j;
                y[count] = i;
                count++;
            }    


        }
    }resetDist();
    findShortest(Coord(x[0],y[0]));
    fout << dist[x[1]][y[1]] + 1 << "\n";
    for (int i = 0; i < 10; ++i)
        fin >> grid[0][0];
}
    
    
    

    
    
    
    
    
    

    return 0;
}

