Crossword Puzzles 

Almost everyone is familiar with crossword puzzles. Here you have to deal with a special kind of crossword puzzle that is adequate for an automated solver. A description of the puzzle and a list of admissible words (the dictionary) is given, and the goal is to find the number of possible solutions, if any exists, for the puzzle using the given dictionary.

The puzzle is represented as a grid of white and black squares. A solution is a subset of dictionary words that fill all the sequences of horizontal or vertical white squares in such a way that all the horizontal and vertical crossings formed are still valid dictionary words. One-letter sequences do not need to be in the dictionary.

An example of a crossword puzzle in which white and black squares are respectively represented by the `.' and `#' characters, a word dictionary and a solution for the puzzle is as follows:

. . . . . . . . . .     aa ac al alao ali ap        v a r i e d a d e s
. . . . . # . . . .     atencao atlanta camilo      e p o c a # t u l e
. # . . . . . . # .     doar dr duo eam eis el      r # c a m i l o # n
. . . . # . . # . .     epoca et icar ileso is      d o a r # l a # s i
. . # # . . . # . .     la loto mal men             a a # # m e n # a l
. . # . . . . . # #     merito mi no                d r # r e s t o # #
. . . # . . . # . .     oaristo oo os pios          e i s # r o a # a p
. . # . . # # . . .     resto roa roca rt           i s # m i # # a l i
. . # . . . . . . .     sa senil si tule            r t # a t e n c a o
. . # . . . . # . .     variedades verdadeiro       o o # l o t o # o s


Your task is to develop a program to solve the described crossword puzzles.

Input 

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.


The input consists of a 10×10 puzzle configuration and a word dictionary. For the puzzle each input line is a sequence of `.' and `#' characters. You may assume that the given configuration is always correct.

The dictionary words start immediately after the last line of the puzzle. Each word is a sequence of lower case letters, without accents and separated by spaces. The dictionary terminates when the end-of-file is reached from the standard input.

Output 

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.


The program should output the number of solutions that the given crossword puzzle accepts.

Sample Input 

1

..........
.....#....
.#......#.
....#..#..
..##...#..
..#.....##
...#...#..
..#..##...
..#.......
..#....#..
aa ac al alao
ali ap atencao
atlanta camilo
doar dr duo eam
eis el epoca et
icar ileso is
la loto mal men
merito mi no
oaristo oo os pios
resto roa roca rt
sa senil si tule
variedades verdadeiro

Sample Output 

1



Pedro Vasconcelos, ACM-UP'2000