//* Problem  : 2951 - NPUZZLE
//* Contest  : acm.tju.edu.cn
//* Origin   : 
//* Type     : Solution
//* Date     : 2008.04.29
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0
//* Algoritm : 

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <iostream>
using namespace std;
#define int64 long long

#define PI 2*acos(0.0)

int res; char a[8][8];

int main()
{
#ifdef _DEBUG
	freopen("1366", "r", stdin);
#endif
	gets(a[0]);gets(a[1]);gets(a[2]);gets(a[3]);
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++)
			if (a[i][j] != '.')
				res += abs(i - (a[i][j] - 'A')/4) + abs(j - ((a[i][j] - 'A')%4));
		//	else
		//		res += 3 - i + 3 - j;
	printf("%d\n", res);
	return 0;
}
