
import java.util.*;
import java.io.*;
import java.math.*;

public class P3 {
	static char map[][]=new char[10][10];
	static  int destX;
	static int destY;
	public static void main(String args[]) throws IOException
	{
		Scanner sc=new Scanner(new FileReader("DATA3.txt"));
		PrintWriter pw=new PrintWriter(new FileWriter("OUT3.txt"));
		
		for(int LL=0;LL<5;LL++)
		{
			for(int i=0;i<10;i++)
			{
				String line=sc.next();
				for(int j=0;j<10;j++)
				{
					map[i][j]=line.charAt(j);
					if(map[i][j]=='A')
					{
						destY=i;
						destX=j;
						map[i][j]='#';
					}
				}
			}
			
			
			
			for(int i=0;i<10;i++)
			{
				for(int j=0;j<10;j++)
				{
					if(map[i][j]=='#')
					{
						char tmp[][]=new char[10][10];
						for(int k=0;k<10;k++)
						{
							for(int l=0;l<10;l++)
							{
								tmp[k][l]=map[k][l];
							}
						}
						if(isDisconnected(j, i, tmp))
						{
							kill(j, i);
						}
					}
				}
			}
			int count=0;
			for(int i=0;i<10;i++)
			{
				for(int j=0;j<10;j++)
				{
					if(map[i][j]=='#')
					{
						count++;
					}
				}
			}
			pw.println(count);
			
			pw.flush();
			sc.next();
		}
		
		sc.close();
		pw.close();
	}
	
	public static void kill(int xPos, int yPos)
	{

		if(inRange(xPos, yPos) && map[yPos][xPos]=='#')
		{
			map[yPos][xPos]='.';
			kill(xPos+1, yPos);
			kill(xPos-1,yPos);
			kill(xPos, yPos+1);
			kill(xPos, yPos-1);

		}
		
		
		
		
	}
	
	public static boolean isDisconnected(int xPos, int yPos, char tmp[][])
	{
		boolean dis=true;

		if(inRange(xPos, yPos) && tmp[yPos][xPos]!='.')
		{			
			tmp[yPos][xPos]='.';

			if(yPos==destY && xPos==destX)
			{
				dis=false;
			}
			else if(!isDisconnected(xPos+1, yPos, tmp))
			{
				dis=false;
			}
			else if(!isDisconnected(xPos-1,yPos, tmp))
			{
				dis=false;
			}
			else if(!isDisconnected(xPos, yPos+1, tmp))
			{
				dis=false;
			}
			else if(!isDisconnected(xPos, yPos-1, tmp))
			{
				dis=false;
			}
		}
		
		return dis;
		
	}
	
	public static boolean inRange(int xPos, int yPos)
	{
		return 0<=xPos && 0<=yPos && xPos<10 && yPos<10;
	}
}

