#include <iostream>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <string>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?b:a)
#define fori(n) for (int i = 0; i < n; i++) 
#define forj(n) for (int j = 0; j < n; j++)

using namespace std;
int r,c;
int oob(int rr, int cc){
	return (rr >= r || rr < 0 || cc >= c || cc <0); 
}

int main() {
	ifstream in ("DATA5.txt");	// IS THIS THE RIGHT NUMBER?
	ofstream out ("OUT5.txt");  // IS THIS THE RIGHT NUMBER?
	
	for (int Z = 0; Z < 5; Z++) {
		int w;
		in >> w >> c >> r;
		string map[r];
		string fill[r];
		getline(in,map[0]); 
		fori(r){
			getline(in,map[i]);
			fill[i] = map[i];
		}
		fori(w){
			int rr,cc;
			rr = 0; cc = 0;
			while(1){
				/*for(int x=0; x<r; x++){
					for(int y=0; y<c; y++){
						if(x == rr && y == cc) cout << '*';
						else cout << fill[x][y];
					}
					cout << endl;
				}
				cout << endl;*/
				if(!oob(rr+1,cc) && fill[rr+1][cc] != '#') rr++;
				else if(!oob(rr,cc+1) && fill[rr][cc+1] != '#') cc++;
				else break;
				
			}
			fill[rr][cc] = '#';
			//cout << "Done " << i << endl;
		}
		int n=0;
		fori(r){
			forj(c){
				if(map[i][j] == 'A' && fill[i][j] == '#') n++;
			}
		}
		out << n << endl;
	}
	
	//getchar();		// REMOVE THIS BEFORE SUBMITTING
	return 0;
}

