#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;

ifstream in("DATA5.txt");
ofstream out("OUT5.txt");

int main(){
	for (int prb = 0; prb != 5; ++prb){
		int water, c, r;
		in >> water >> c >> r;
		string s;
		vector<string> map;
		for (int i=0; i!=r; ++i){
			in >> s;
			map.push_back(s);
		}
		int attr = 0;
		for (int i=0; i!=water; ++i){
			int x=0, y=0;
			while(1){
				while (y+1!=r && map[y+1][x] != '#') ++y;
				if (x+1==c || map[y][x+1] == '#') break;
				++x;
			}
			if (map[y][x] == 'A') ++attr;
			map[y][x] = '#';
		}
		/*for (int i=0; i!=r; ++i){
			cout << map[i] << '\n';
		}*/
		out << attr << '\n';
	}
	//system("pause");
	return 0;
}
