#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <ctime>

#define forr(a,b,c) for(int (a) = (b); (a) < (c); ++ (a))
#define fore(a,b,c) for(int (a) = (b); (a) <= (c); ++ (a))

#define pii pair<int,int>
#define int3 pair<pair<int,int>, int>
#define vi vector<int>
#define ull long long
#define vs vector<string>

//#define DEBUG

using namespace std;

string maze[12];
int w[100][100];

pair<int,int> getice(int r, int c, int dr, int dc){
	while(1){
		if(maze[r+dr][c+dc] == '#') return make_pair(r,c);
		r+=dr;
		c+=dc;
	}
	return make_pair(0,0);
}

int main(){
	
	#ifndef DEBUG
		freopen("DATA5.txt", "r", stdin);
		freopen("OUT5.txt", "w", stdout);
	#endif
	
	maze[0] = maze[11] = "############";
	for(int i=1; i<11; ++i){ 
		cin >> maze[i];
		maze[i] = "#" + maze[i] + "#";
	}
	
	pair<int,int> points[6];
	for(int i=0; i<12; ++i){ 
		for(int j=0; j<12; ++j){
			if(maze[i][j]!='.' && maze[i][j]!='#'){
				points[maze[i][j]-'A'] = make_pair(i-1,j-1);
			}
		}
	}
	
	int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
	forr(i,0,100) forr(j,0,100) w[i][j] = 99999;
	
	for(int i=1; i<11; ++i){ 
		for(int j=1; j<11; ++j){
			for(int drc=0; drc<4; ++drc){
				pair<int,int> p = getice(i, j, dir[drc][0], dir[drc][1]);
				w[(i-1)*10 + j-1][(p.first-1)*10 + p.second-1] =
				abs(p.first-i) + abs(p.second-j)
				;
			}
		}
	}
	
	for(int k=0;k<100; ++k){
		for(int i=0; i<100; ++i){
			for(int j=0; j<100; ++j){
				w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
			}
		}
	}
	
	for(int i=0; i<5; ++i){
		cout << w[points[i].first*10 + points[i].second][points[i+1].first*10 + points[i+1].second] << '\n';
	}
	
	#ifdef DEBUG
		system("pause");
	#endif
	
	return 0;
}

