Sanggeun and Jeongin sat down for a game of chess and found the white king missing. They decided to play a modified game instead. Sanggeun has two rooks (♖) and Jeongin has only a king (♚). It is Sanggeun's turn.
Sanggeun wants to win by checkmate and Jeongin defends as well as he can. Jeongin avoids checkmate whenever he can, and when he cannot, he stretches the game out for as many of Sanggeun's moves as possible. Given that both play this way, find the smallest number of moves Sanggeun needs to win.
The rules are these.
The first line contains the number of test cases.
Each test case is one line holding the square of Jeongin's king followed by the squares of Sanggeun's two rooks, separated by spaces. A square is written as a lowercase letter from a to h for the file, then a digit from 1 to 8 for the rank.
No two pieces stand on the same square, and Jeongin's king is never in check in the given position.
For each test case, print the smallest number of moves Sanggeun needs to win, one per line. Print 0 if he cannot win.