Mini Sudoku X

No attempts yetTime limit1sMemory limit256 MB

Problem

Mini Sudoku X is played on a 6 × 6 grid of digits. The grid is a correct solution when every one of these groups holds each digit from 1 to 6 exactly once:

  • each of the 6 rows
  • each of the 6 columns
  • the diagonal that runs from the top left cell to the bottom right cell
  • the diagonal that runs from the top right cell to the bottom left cell
  • each of the 6 blocks of 2 rows by 3 columns, that is rows 1 and 2, rows 3 and 4, or rows 5 and 6 crossed with columns 1 to 3 or columns 4 to 6

The grid below is a correct solution. The cells on the two diagonals are shaded.

Read a grid of 36 digits and decide whether it is a correct solution.

Input

The first line has a positive integer TT (T100000T \le 100000), the number of test cases. The test cases follow.

Each test case is six lines, and each line has six 1-digit integers separated by a space. A 1-digit integer is not always between 1 and 6, and a grid that holds a digit outside that range is not a correct solution.

Output

For each test case print one line of the form Case#x: M, where x is the case number starting from 1, and M is 1 when that test case is a correct solution and 0 when it is not. There is no space between Case and #.