#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;
char map[10][10];
int floodfill(int x, int y)
{
    if(x>=0 && x < 10 && y >= 0 &&y < 10)
    {
        if(map[x][y] == '.')
        {
            return 0;
        }
        else
        {
            map[x][y] = '.';
            return 1+floodfill(x-1,y)+floodfill(x+1,y)+floodfill(x,y-1)+floodfill(x,y+1);
        }
    }
    return 0;
}
int main()
{
    freopen("DATA3.txt", "r", stdin);
    freopen("OUT3.txt", "w", stdout);
    for(int j = 0; j < 5; j++)
    {
        int locx, locy;
        for (int y = 0; y < 10; y++)
        {
            for (int x = 0; x < 10; x++)
            {
                cin >> map[x][y];
                if (map[x][y] == 'A')
                {
                    locx = x;
                    locy = y;
                }
            }
        }
        cout << floodfill(locx,locy) << endl;
        string blank;
        cin >> blank;
    }



    return 0;
}

