P14114 [IAMOI R4] Queen

Description

Little T likes to play chess, so Little Y decides to give her a challenge. Given an $n \times m$ chessboard, Little Y places a queen$^\dag$ at position $(x_1, y_1)$. Little T needs to move the queen to $(x_2, y_2)$ in as few moves as possible. To increase the difficulty, Little Y will place an obstacle on a single square, other than the starting and ending squares. The queen cannot pass through this obstacle. Little Y wants to place this obstacle to maximize the number of moves Little T needs. Assuming both players adopt their optimal strategies, what is the number of moves Little T will take? $^\dag$: The queen is a piece in international chess. In a single move, it can move any number of squares in one of the eight directions (horizontally, vertically, and diagonally).

Input Format

**This problem contains multiple test cases.** The first line of the input contains an integer $T$, representing the number of test cases. This is followed by $T$ test cases. For each test case, a single line contains six positive integers: $n, m, x_1, y_1, x_2, y_2$.

Output Format

For each test case, output a single line containing an integer, which is the answer.

Explanation/Hint

**【Sample Explanation】** For the first test case, the queen is already at the target position, so 0 moves are needed. For the second test case, Little Y might place the obstacle at $(2,2)$. Little T can then move the queen first to $(3,1)$ and then to $(3,3)$, taking 2 moves. For the third test case, Little Y might place the obstacle at $(1,2)$. Little T can then move the queen first to $(2,1)$, then to $(2,5)$, and finally to $(1,5)$, taking 3 moves. **【Data Constraints】** | Test Case # | $n \le$ | $m \le$ | Special Properties | | :---: | :---: | :---: | :---: | | $1$ | $2$ | $2$ | None | | $2$ | $3$ | $3$ | ^ | | $3$ | $4$ | $4$ | ^ | | $4$ | $5$ | $5$ | ^ | | $5$ | $2$ | $100$ | ^ | | $6$ | $100$ | ^ | ^ | | $7$ | $2$ | $10^9$| $x_1=x_2$ | | $8$ | $10^9$| ^ | ^ | | $9$ | $2$ | ^ | None | | $10$| $10^9$| ^ | ^ | For all test cases, it is guaranteed that: $1 \le T \le 20$, $2 \le n, m \le 10^9$.