SUDOKU - Sudoku

no tags 

A Sudoku grid is a 16x16 grid of cells grouped in sixteen 4x4 squares, where some cells are filled with letters from A to P (the first 16 capital letters of the English alphabet), as shown in the figure. The game is to fill all the empty grid cells with letters from A to P such that each letter from the grid occurs once only in the line, the column, and the 4×4 square it occupies. The initial content of the grid satisfies the constraints mentioned above and guarantees a unique solution.

A C O I
J A B P C G F H
D F I E P
G E L H M J
E C G
I K G A B E J
D G P J F A
E C B D P O
E F M D L K A
C O I L
H P C F A B
G O D J H
K J H A P L
B P E K A
H B K F I C
F C D H N

a) Sudoku grid


F P A H M J E C N L B D K O G I
O J M I A N B D P K C G F L H E
L N D K G F O I J E A H M B P C
B G C E L K H P O F I M A J D N
M F H B E L P O A C K J G N I D
C I L N K D G A H B M O P E F J
D O G P I H J M F N L E C A K B
J E K A F C N B G I D P L H O M
E B O F P M I J D G H L N K C A
N C J D H B A E K M O F I G L P
H M P L C G K F I A E N B D J O
A K I G N O D L B P J C E F M H
K D E M J I F N C H G A O P B L
G L B C D P M H E O N K J I A F
P H N O B A L K M J F I D C E G
I A F J O E C G L D P B H M N K

b) Solution


Input

The first line of the input contains an integer K - determining the number of datasets (K <= 10). Each data set encodes a grid and contains 16 strings on 16 consecutive lines as shown in the example input below. The ith string stands for the ith line of the grid, is 16 characters long, and starts from the first position of the line. String characters are from the set {A, B ... P, -}, where – (minus) designates empty grid cells. The data sets are separated by single empty lines.

Output

For each data set in the input print the completed 16×16 Sudoku as specified by the rules above. The program prints the solution of the input encoded grids in the same format and order as used for input. The output for each data set should be separated by single empty lines.

Example

Input:
1
--A----C-----O-I
-J--A-B-P-CGF-H-
--D--F-I-E----P-
-G-EL-H----M-J--
----E----C--G---
-I--K-GA-B---E-J
D-GP--J-F----A--
-E---C-B--DP--O-
E--F-M--D--L-K-A
-C--------O-I-L-
H-P-C--F-A--B---
---G-OD---J----H
K---J----H-A-P-L
--B--P--E--K--A-
-H--B--K--FI-C--
--F---C--D--H-N-

Output:
FPAHMJECNLBDKOGI
OJMIANBDPKCGFLHE
LNDKGFOIJEAHMBPC
BGCELKHPOFIMAJDN
MFHBELPOACKJGNID
CILNKDGAHBMOPEFJ
DOGPIHJMFNLECAKB
JEKAFCNBGIDPLHOM
EBOFPMIJDGHLNKCA
NCJDHBAEKMOFIGLP
HMPLCGKFIAENBDJO
AKIGNODLBPJCEFMH
KDEMJIFNCHGAOPBL
GLBCDPMHEONKJIAF
PHNOBALKMJFIDCEG
IAFJOECGLDPBHMNK

hide comments
Thotsaphon Thanatipanonda: 2015-12-24 10:41:04

Simple and Challenging for my 1000th problems.


Added by:P.Kasthuri Rangan­
Date:2006-11-24
Time limit:2.640s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:ACM Southeastern European Regional Programming Contest - 2006