Hexagon Perplexagon

Time limit2sMemory limit128 MB

Problem

A well-known puzzle consists of 7 hexagonal pieces, each with the numbers $1$ through $6$ printed on its six sides. Every piece has a different arrangement of the numbers on its sides. The goal is to place the 7 pieces in the arrangement described below so that the two numbers meeting on every shared edge are equal.

The arrangement is a flower: one piece is placed in the center, and the other six pieces surround it. Each of the six outer pieces shares one edge with the central piece and one edge with each of its two neighboring outer pieces, for 12 shared edges in total, and on every shared edge the numbers shown by the two pieces must be identical.

Pieces may be rotated in place, but they may not be flipped over.

Rotating an entire solution yields another, trivially identical solution. To avoid this redundancy, we only consider solutions in which the number $1$ is on the uppermost edge of the central piece.

Input

The first line of the input contains a single integer, the number of test cases.

Each test case is a single line containing 42 integers. The first 6 are the values on the six sides of piece 0 listed in clockwise order, the next 6 are the values on piece 1, and so on; the 42 integers thus describe pieces 0 through 6 in order.

Output

For each test case, print a line that begins with Case k: (where $k$ is the test case number, starting from 1), followed by either the phrase No solution or a solution specification.

A solution specification lists the piece numbers as follows: first the number of the central piece, then the six outer pieces starting from the topmost piece and proceeding clockwise. For example, if piece 3 is in the center it is printed first, and if piece 0 is at the top it is printed next.

Each test case is guaranteed to have at most one solution.