Under construction

Still being built. Things may change

Mini Sudoku X

Interview

Time limit1sMemory limit256 MB

Summary
Read 6 by 6 grids and report whether each row, column, diagonal, and 2 by 3 block holds digits 1 to 6 exactly once.
Level

Easy3 of 10

Topics
Implementation, Matrix
Solved
No attempts yet

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 (T≤100000T \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 #.

Examples1

  1. Example 1

    Input
    10
    1 1 4 3 6 4
    3 2 3 5 2 1
    4 2 3 2 2 3
    2 6 4 3 3 2
    2 3 1 2 3 3
    4 6 3 1 3 5
    2 5 3 3 5 2
    2 1 6 4 4 4
    5 6 1 1 5 2
    1 4 3 4 1 1
    6 1 5 3 4 3
    4 1 3 2 5 1
    2 6 4 3 4 4
    1 2 2 4 5 3
    1 3 3 2 6 1
    2 6 3 2 2 4
    4 3 5 1 1 2
    4 3 6 2 5 5
    4 1 6 2 4 3
    3 1 1 1 1 1
    1 2 1 1 6 1
    4 6 3 5 1 5
    5 3 2 2 1 1
    4 6 4 1 2 3
    2 1 6 1 1 2
    3 5 4 2 3 4
    3 2 4 2 5 3
    3 3 2 4 4 6
    4 4 4 3 4 3
    4 4 3 1 4 3
    3 4 1 6 2 5
    6 5 2 4 3 1
    1 3 4 2 5 6
    5 2 6 1 4 3
    2 1 3 5 6 4
    4 6 5 3 1 2
    3 5 4 2 3 1
    5 2 1 3 2 4
    4 1 3 6 2 6
    2 3 4 1 2 4
    3 2 4 4 3 1
    5 2 5 4 2 4
    3 2 1 3 2 5
    2 4 4 4 2 2
    1 6 4 5 1 5
    6 6 3 3 6 3
    1 4 4 6 3 2
    3 3 1 2 4 1
    1 3 4 4 3 2
    3 6 1 4 1 1
    3 4 5 1 2 5
    2 1 5 1 3 2
    2 6 3 1 2 2
    4 2 2 2 2 1
    4 1 3 5 3 4
    1 5 4 4 3 3
    4 5 1 2 5 1
    4 1 5 5 1 2
    3 5 3 6 2 6
    3 4 6 3 3 5
    
    Expected output
    Case#1: 0
    Case#2: 0
    Case#3: 0
    Case#4: 0
    Case#5: 0
    Case#6: 1
    Case#7: 0
    Case#8: 0
    Case#9: 0
    Case#10: 0