Top This

Time limit1sMemory limit128 MB

Problem

The game Top This uses pieces made of four unit squares joined edge to edge, so that every square shares a full side with at least one other square. There are exactly seven such pieces, labeled A through G (each # is a filled unit square):

A      B      C      D      E      F      G
####   #.     ###    .#     ##.    ##     .##
       #.     .#.    .#     .##    ##     ##.
       ##            ##

You are given three red pieces and three blue pieces. First arrange the three red pieces on a grid so that they do not overlap (they may touch along edges). Then arrange the three blue pieces so that, together, they cover exactly the same set of squares as the red pieces.

You may rotate each piece to any orientation, but you may not flip it over. Flipping would turn piece B into piece D and vice versa, and would likewise swap E and G.

Your task is to report a shape that can be built from both the red pieces and the blue pieces. Only consider shapes that fit inside a $6 \times 6$ grid. There may be more than one valid shape; you must report the one that comes first in the ordering below.

To compare two shapes, examine their cells in row-major order (left to right within each row, starting with the top row) until you reach the first cell where the two shapes differ. The shape whose cell is filled there comes before the shape whose cell is empty.

Input

The first line contains an integer $T$ ($1 \le T \le 5$), the number of data sets. Each of the next $T$ lines describes one data set: a string of three characters, a single space, and then another string of three characters. Each character is an uppercase letter from A to G naming one of the seven pieces. The first three characters are the red pieces; the last three characters are the blue pieces.

Output

For each data set, first print the data set's number on its own line ($1$ for the first data set, $2$ for the second, and so on). After that, print the solution as six lines of six characters each, where # marks a filled square and . marks an empty square. The filled squares must describe the first shape (under the ordering defined above) that can be formed by both the red pieces and the blue pieces. If there is no such shape, print No solution on a single line instead.