Each chessboard has numbers written on each square and is supplied with 8 chess queens. The task is to place the 8 queens on the chessboard in such a way that no queen threatens another one, and so that the sum of the numbers on the squares selected is the minimum. (For those unfamiliar with the rules of chess, this implies that each row and column of the board contains exactly one queen, and each diagonal contains no more than one queen.)
Write a program that will read in the number and details of the chessboards and determine the lowest scores possible for each board under these conditions.
Input will consist of K (the number of boards), on a line by itself, followed by K sets of 64 numbers, each set consisting of eight lines of eight numbers. Each number will be a non-negative integer less than 10000. Each case is separated by a blank line. There will never be more than 20 boards.
The outputs of all test cases should be printed in order. For each test case a line, print the lowest score.