Doubly-sorted grid (small)

No attempts yetTime limit5sMemory limit512 MB

Problem

A rectangular grid holds one lower case English letter in each cell. The grid is doubly sorted if the letters in every row are non-decreasing from left to right, and the letters in every column are non-decreasing from top to bottom. Of the four grids below, the first two are doubly sorted and the other two are not.

abc    ace    aceg    base
def    ade    cdef    base
ghi    bdg    xxyy    base

You are given a grid in which only some of the cells are filled. Count the ways to fill the remaining cells so that the whole grid is doubly sorted. The answer can be large, so print the number of ways modulo 1000710007.

Input

The first line contains the number of test cases TT. Then TT test cases follow. The first line of each test case contains the number of rows RR and the number of columns CC, separated by a space. The next RR lines each contain a string of length CC, and those strings describe the partially filled grid. Each character of the grid is either a lower case English letter or ., which marks a cell that is not filled yet.

Limits

  • 1T401 \le T \le 40
  • 1R,C41 \le R, C \le 4
  • Each character of the grid is . or a lower case English letter.

Output

For each test case, print one line in the format Case #X: y, where XX is the test case number starting from 1 and yy is the number of doubly sorted grids you can obtain, modulo 1000710007.