#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define mp(a, b) (make_pair(a, b))
using namespace std;
const int maxn=5+10, maxm=(1<<10)+10, mod=772002;
typedef long long lint;
int ans, T, n, m, dd[9][2]={-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1, 0, 0};
char mp[maxn][maxn];
bool Judge()
{
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++) if(mp[i][j]=='X')
			for(int k=0; k<8; k++)
				if(mp[i+dd[k][0]][j+dd[k][1]]=='X')	return false;
	return true;
}
int DP()
{
	vector<pair<int, int> > vct;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++) if(mp[i][j]=='X')
			vct.push_back(mp(i, j));
	int len=vct.size(), lim=(1<<vct.size()), tmp=n*m;
	int cnt[maxm]={0}, f[maxn*maxn][maxm]={0};
	for(int st=0; st<lim; st++)
	{
		bool u[maxn][maxn]={false};
		for(int i=0; i<len; i++)
			if(!(st&(1<<i))) u[vct[i].first][vct[i].second]=true;
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m; j++)
			{
				bool f=true;
				for(int k=0; k<9&&f; k++) f&=!u[i+dd[k][0]][j+dd[k][1]];
				f&&(++cnt[st]);
			}
	}
	f[0][0]=1;
	for(int i=1; i<=tmp; i++)
		for(int st=0; st<lim; st++) 
		{
			f[i][st]=(f[i][st]+(lint)f[i-1][st]*max(cnt[st]-i+1, 0)%mod)%mod;
			for(int j=0; j<len; j++) if(st&(1<<j))
				f[i][st]=(f[i][st]+f[i-1][st^(1<<j)])%mod;
		}
	return f[tmp][lim-1];
}
void Dfs(int x, int y, int cnt)
{
	if(x==n+1)
	{
		ans=(ans+DP()*(cnt&1 ? -1 : 1)+mod)%mod;
		return ;
	}
	int tx=(y==m ? x+1 : x), ty=(y==m ? 1 : y+1);
	Dfs(tx, ty, cnt);
	for(int i=0; i<9; i++) if(mp[x+dd[i][0]][y+dd[i][1]]=='X')	return ;
	mp[x][y]='X';
	Dfs(tx, ty, cnt+1);
	mp[x][y]='.';
	return ;
}
int main()
{
	while(scanf("%d%d", &n, &m)!=EOF)
	{
		for(int i=1; i<=n; i++)	scanf("%s", mp[i]+1);
		if(!Judge())	printf("Case #%d: 0\n", ++T);
		else	ans=0, Dfs(1, 1, 0), printf("Case #%d: %d\n", ++T, ans);
	}
	return 0;
}