Quadrilles

A domino is a rectangular tile of size 2×1, where each end has a certain number of dots (between 0 and 6). A standard double-six domino set contains 28 different dominoes, namely precisely all possible combinations of the number of dots on both ends. A quadrille is a layout of the standard double-six domino set so that they form the following pattern: the layout can be partitioned into 14 2×2 squares such that the number of dots in the 4 tiles in a square are the same. The picture below shows an example of a quadrille. Given the shape of the layout, determine how many (if any) different quadrilles exist with that shape. Two quadrilles are considered different if one of them is not just a permutation of the number of dots in each (2×2) square (there are, of course, 7! = 5040 such permutations). Note however that two different layouts may yield the same number of dots in each (2×2) square (this is demonstrated by the second sample below). Quadrilles that are horizontal and/or vertical mirrors of each other are considered different. Input The first line in the input will contain the number of shapes (no more than 10). The shapes will then be described in 12×8 matrices with the characters ‘X’ (marking areas which a domino must cover) and ‘.’ (marking areas which should not be covered by a domino) – see the sample input for the exact format. Each shape will be preceeded by a blank line. You may assume that each shape can be partitioned into exactly 14 (2×2) squares. Output For each shape, output a single integer on a line by itself: the number of different quadrilles that have this shape. Notes: Sample 1: The two solutions are horizontal mirrors of each other. Sample 2: Among the solutions, there are several layouts that give the same number of dots in each (2×2) square. For instance, there are two different ways to place the dominoes so that the quadrille below appears. Both these ways should be counted.

2/2 ...00112233. ...00112233. ....445500.. ....445500.. ....661166.. ....661166.. ...22443355. ...22443355. Sample Input 2 .XXXXXX..... .XXXXXX..... XXXXXXXX.... XXXXXXXX.... .XXXXXX..... .XXXXXX..... XXXXXXXX.... XXXXXXXX.... ...XXXXXXXX. ...XXXXXXXX. ....XXXXXX.. ....XXXXXX.. ....XXXXXX.. ....XXXXXX.. ...XXXXXXXX. ...XXXXXXXX. Sample Output 2 136