#K67602. Minimum King Moves on a Chessboard
Minimum King Moves on a Chessboard
Minimum King Moves on a Chessboard
Given two positions on an 8×8 chessboard in standard chess notation (e.g., a1, h8), determine the minimum number of moves a king requires to travel from the start position to the end position. The king moves one square in any direction (horizontally, vertically, or diagonally). Mathematically, if the coordinates of the start and end positions are ((x_1, y_1)) and ((x_2, y_2)) respectively, then the minimum moves required is:
[ \text{moves} = \max(|x_2-x_1|,\ |y_2-y_1|) ]
Read input from standard input (stdin) and print the result to standard output (stdout).
inputFormat
The first line of input contains an integer (T), the number of test cases. Each of the following (T) lines contains two strings separated by a space, representing the starting and ending positions on the chessboard. For example:
4 a1 b3 h8 a1 d4 e5 g6 g7
outputFormat
For each test case, output a single integer on a new line representing the minimum number of king moves required to go from the starting position to the ending position.## sample
4
a1 b3
h8 a1
d4 e5
g6 g7
2
7
1
1
</p>