Mountain

Time Limit: 1500ms
Memory Limit: 65536KB
This problem will be judged on HDU. Original ID: 5838
64-bit integer IO format: %I64d      Java class name: Main

Description

Zhu found a map which is a $N * M$ rectangular grid.Each cell has a height and there are no two cells which have the same height. But this map is too old to get the clear information,so Zhu only knows cells which are valleys.

A cell is called valley only if its height is less than the heights of all its adjacent cells.If two cells share a side or a corner they are called adjacent.And one cell will have eight adjacent cells at most.

Now give you $N$ strings,and each string will contain $M$ characters.Each character will be '.' or uppercase 'X'.The j-th character of the i-th string is 'X' if the j-th cell of the i-th row in the mountain map is a valley, and '.' otherwise.Zhu wants you to calculate the number of distinct mountain maps that match these strings.

To make this problem easier,Zhu defines that the heights are integers between $1$ and $N*M$.Please output the result modulo $772002$.

Input

The input consists of multiple test cases.

Each test case begins with a line containing two non-negative integers $N$ and $M$. Then $N$ lines follow, each contains a string which contains $M$ characters. $(1 \leq N \leq 5,1 \leq M \leq 5)$.

Output

For each test case, output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer after module 772002.

Sample Input

2 4
.X..
...X
4 2
X.
..
..
X.
1 2
XX

Sample Output

Case #1: 2100
Case #2: 2520
Case #3: 0

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .