#include<bits/stdc++.h>usingnamespace std;constint N =25;constint dx[4]={1,0,-1,0};constint dy[4]={0,-1,0,1};char g[N][N];int n, m;int sx,sy;bool st[N][N];intdfs(int x,int y){int res =1;
st[x][y]=true;for(int k =0; k <4; k++){int nx = x + dx[k], ny = y + dy[k];if(nx >=0&& nx < n && ny >=0& ny < m){if(g[nx][ny]=='.'&&!st[nx][ny]){
res +=dfs(nx,ny);}}}return res;}intmain(){while(cin >> m >> n && n && m){memset(st,0,sizeof st);for(int i =0; i < n; i++){for(int j =0; j < m; j++){
cin >>g[i][j];if(g[i][j]=='@'){
sx = i, sy = j;}}}
cout <<dfs(sx,sy)<< endl;}return0;}
#include<bits/stdc++.h>usingnamespace std;constint N =10;constint dx[8]={2,1,-1,-2,-2,-1,1,2};constint dy[8]={-1,-2,-2,-1,1,2,2,1};bool st[N][N];int T, n, m;int ans;int sx,sy;voiddfs(int x,int y,int cnt){if(cnt == n * m){
ans ++;return;}for(int k =0; k <8; k++){int nx = x + dx[k], ny = y + dy[k];if(nx >=0&& nx < n && ny >=0&& ny < m){if(!st[nx][ny]){
st[nx][ny]=true;dfs(nx,ny,cnt+1);
st[nx][ny]=false;}}}}intmain(){
cin >> T;while(T --){memset(st,0,sizeof st);
ans =0;
cin >> n >> m >> sx >> sy;
st[sx][sy]=true;dfs(sx,sy,1);
cout << ans << endl;}return0;}