Tight-Fit Sudoku

Time limit2sMemory limit512 MB

Summary
Fill a 6 by 6 grid with digits 1 to 9 so no digit repeats in a row, column, or 3 by 2 box, including split squares holding two digits.
Level

Medium7 of 10

Topics
Backtracking, Implementation, Matrix
Solved
No attempts yet

Problem

At some point or another, most computer science students have written a standard Sudoku solving program. A slight twist has been added to standard Sudoku to make it a bit more challenging.

Digits from 1 to 9 are entered in a 6×66 \times 6 grid so that no number is repeated in any row, column, or outlined 3×23 \times 2 region. A 3×23 \times 2 region is 3 squares wide and 2 squares tall; splitting the grid into groups of 2 rows from the top and groups of 3 columns from the left gives the 6 regions. Some squares in the grid are split by a slash (/) and need 2 digits entered in them. The smaller number always goes above the slash.

Write a program that takes an incomplete puzzle grid as input and outputs the puzzle solution grid.

Input

The first line of input contains a single decimal integer PP (1≤P≤1001 \le P \le 100), the number of data sets that follow.

Each data set should be processed identically and independently. Each data set consists of 7 lines of input. The first line of the data set contains the data set number, KK. The remaining 6 lines represent an incomplete Tight-Fit Sudoku grid; each line has 6 data elements, separated by spaces. A data element is a digit (1 to 9), a - for a blank square, or two of these joined by a slash (/). An element with a slash is a split square: the part before the slash is the upper half, and the part after it is the lower half.

Every grid has exactly one solution.

Output

For each data set there are 7 lines of output. The first output line is the data set number, KK. The following 6 lines show the solution grid for that data set. Each line has 6 data elements, separated by spaces. A data element is a single digit (1 to 9) or 2 digits separated by a slash (/). For a split square, write the smaller digit before the slash.

Examples1

  1. Example 1

    Input
    1
    1
    -/- -/5 4 3 2 -/-
    - 6 -/- -/- - -/-
    - 7/- - -/- -/- 2
    8 -/- -/- - -/3 -
    -/- - -/- -/- 4 -
    -/- 8 7 6 5/- -/-
    
    Expected output
    1
    7/9 1/5 4 3 2 6/8
    3 6 2/8 1/9 7 4/5
    1 7/9 3 4/5 6/8 2
    8 2/4 5/6 7 1/3 9
    5/6 3 1/9 2/8 4 7
    2/4 8 7 6 5/9 1/3