Problem J. Problem J. Let Sudoku Rotate

时间限制 1000 ms   内存限制 256 MB

Sudoku is a logic-based, combinatorial number-placement puzzle, which is popular around the world.
In this problem, let us focus on puzzles with $16 \times 16$ grids, which consist of $4 \times 4$ regions. The objective is to fill the whole grid with hexadecimal digits, i.e. 0123456789ABCDEF, so that each column, each row, and each region contains all hexadecimal digits. The figure below shows a solved sudoku.



Yesterday, Kazari solved a sudoku and left it on the desk. However, Minato played a joke with her - he performed the following operation several times.
* Choose a region and rotate it by 90 degrees counterclockwise.
She burst into tears as soon as she found the sudoku was broken because of rotations.
Could you let her know how many operations her brother performed at least?
 

输入数据

The first line of the input contains an integer $T$ $(1 \le T \le 10 ^ 3)$ denoting the number of test cases.
Each test case consists of exactly $16$ lines with $16$ characters each, describing a broken sudoku.
 

输出数据

For each test case, print a non-negative integer indicating the minimum possible number of operations.
 

样例输入

复制
1
681D5A0C9FDBB2F7
0A734B62E167D9E5
5C9B73EF3C208410
F24ED18948A5CA63 
39FAED5616400B74 
D120C4B7CA3DEF38 
7EC829A085BE6D51 
B56438F129F79C2A 
5C7FBC4E3D08719F 
AE8B1673BF42A58D 
60D3AF25619C30BE
294190D8EA57264C 
C7D1B35606835EAB 
AF52A1E019BE4306 
8B36DC78D425F7C9 
E409492FC7FA18D2

样例输出

样例说明

 The original sudoku is same as the example in the statement. 

 
  
 
 

提交

请先 登录

© 2025 FAQs Contact About