Chess
Let's review some fundamental chess rules relevant to this problem. Chess is played by two players, one with white pieces and the other with black. The game unfolds on an 8x8 board, with columns labeled "a" to "h" from left to right, and rows numbered 1 to 8 from bottom to top. Each square on the board may be empty or occupied by a single piece. If a piece A (not a pawn) can move to a square occupied by an opponent's piece B according to the rules, piece B is captured and removed from the board. Thus, all squares a piece can move to are considered "under attack" by that piece. The king cannot move to any square under attack by an opponent's piece. If a player makes a move that places the opponent's king under attack (known as "check"), the opponent must make a move to remove the threat. If no such move is possible, it is called "checkmate."
The king can move one square in any of the 8 directions (left, right, forward, backward, or diagonally). The queen can move any number of squares in any of the 8 directions, but cannot pass through squares occupied by other pieces.
Consider a scenario where there are three pieces on the chessboard: a white king, a white queen, and a black king. It is white's turn to move. What is the minimum number of moves required to guarantee checkmate? The black pieces will make every legal move possible to avoid checkmate.
Input
The program should first read the number TEST_NUM, which indicates the number of test cases. This is followed by the test cases themselves. Each test case is a line containing three cell designations, indicating the positions of the white king, white queen, and black king, respectively, separated by spaces (each cell designation consists of the column letter and the row number combined).
All positions provided are guaranteed to be valid according to chess rules (for instance, the black king is not initially in check).
Output
For each test case, your program should output a single number representing the minimum number of moves required.