#include <iostream>
#include <cmath>
#include <fstream>
#include <string>
using namespace std;

bool grid[10][10];
int counter;

void floodFill(int x, int y) {
     if (x>10||x<0||y>10||y<0) return;
     if (!grid[x][y]) return;
     grid[x][y] = false;
     counter++;
     floodFill(x+1,y);
     floodFill(x-1,y);
     floodFill(x,y+1);
     floodFill(x,y-1);
}

int main() {
	ifstream in;
	in.open("DATA3.txt");
	ofstream out;
	out.open("OUT3.txt");
	
	int n, k, i, j;
	char temp;
	int x, y;
	string nulll;
	for (i=0; i<5; i++) {
        counter = 0;
        for (j=0; j<10; j++) {
            for (k=0; k<10; k++) {
                in >> temp;
                if (temp == 'A') {grid[k][j]=true; x=k;y=j;}
                else if (temp == '#') grid[k][j]=true;
                else grid[k][j]=false;
            }
        }
        floodFill(x,y);
        out << counter << endl;
        getline(in,nulll);
	}

	in.close();
	out.close();
	//system("PAUSE");
	return 0;
}

