Letfs try a dice puzzle. The rules of this puzzle are as follows.
Figure 1: Faces of a die
Figure 2: 3 × 3 × 3 cube
Figure 3: A pair of faces placed against each other
Figure 4: Top and front views of the cube
Your job is to write a program that solves this puzzle.
The input consists of multiple datasets in the following format.
N Dataset_{1} Dataset_{2} ... Dataset_{N}
N is the number of the datasets.
The format of each dataset is as follows.
T_{11} T_{12} T_{13} T_{21} T_{22} T_{23} T_{31} T_{32} T_{33} F_{11} F_{12} F_{13} F_{21} F_{22} F_{23} F_{31} F_{32} F_{33}
T_{ij} and F_{ij} (1 ≤ i ≤ 3, 1 ≤ j ≤ 3) are the faces of dice appearing on the top and front views, as shown in Figure 2, or a zero. A zero means that the face at the corresponding position is unknown.
For each plausible arrangement of dice, compute the sum of the numbers marked on the nine faces appearing on the right side of the cube, that is, with the notation given in Figure 2, ∑^{3}_{i=1}∑^{3}_{j=1}R_{ij}.
For each dataset, you should output the right view sums for all the plausible arrangements, in ascending order and without duplicates. Numbers should be separated by a single space.
When there are no plausible arrangements for a dataset, output a zero.
For example, suppose that the top and the front views are given as follows.
Figure 5: Example
There are four plausible right views as shown in Figure 6. The right view sums are 33, 36, 32, and 33, respectively. After rearranging them into ascending order and eliminating duplicates, the answer should be g32 33 36h.
Figure 6: Plausible right views
The output should be one line for each dataset. The output may have spaces at ends of lines.
4 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 4 3 3 5 2 2 4 3 3 6 1 1 6 1 1 6 1 0 1 0 0 0 2 0 0 0 0 5 1 2 5 1 2 0 0 0 2 0 0 0 3 0 0 0 0 0 0 0 0 0 0 3 0 1
27 24 32 33 36 0