eolymp
bolt
Try our new interface for solving problems
Problems

Queen move!

Queen move!

\includegraphics{https://static.e-olymp.com/content/49/49afb2b5efa727967ee3d946bf91aeec7657b79f.jpg} There are \textbf{8} queens are placed arbitrarily on a chessboard \textbf{8}х\textbf{8}. Each horizontal line contains only one queen and there is no other chess pieces. The Queen can move any number of cells diagonally, vertically or horizontally, but can not jump over other pieces. You must make the minimum number of moves to achieve the position where no queen is under the attack of the other. \InputFile The first positive integer \textbf{T} (\textbf{T} < \textbf{6}) is the number of test cases. Then \textbf{T} blocks are given, each of them contains \textbf{8} integers from \textbf{1} to \textbf{8} -- the numbers of horizontals where the queen from the \textbf{i}-th vertical is situated. The verticals are numbered one after another. All numbers are given in one line, separated with a space. \OutputFile Print in one line for each test case one number - the minimum number of queen moves to achieve the desired position. Do not print spaces between the numbers.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2 1 1 1 1 1 1 1 1 2 4 6 8 3 2 7 5

Output example #1
71