The 8-puzzle is an old fashion game contrived by Sam Loyd in the 1870s. The board of the 8-puzzle is composed of 3x3 grids. There are 8 movable tiles on the board numbered from 1 to 8. The purpose of this game is to arrange the tiles on the board back to the initial state. The tiles can only move toward the space on the board.
There are multiple test cases in the input. The first line is an integer k, denoting the number of test cases. For each test cases there are 3 lines with 3 separated numbers, denoting the state of the 8-puzzle.
For each test case, print the minimum steps needed if this configuration can be solved in 20 steps. Otherwise print "Hard".
2 1 2 3 4 5 6 8 7 0 1 2 3 4 5 6 7 0 8
Hard 1
Migrated from old NTUJ.
No. | Testdata Range | Score |
---|