#Q30. 「一本通 1.4 例 3」Knight Moves

「一本通 1.4 例 3」Knight Moves

Description

Original Source: POJ 1915

Write a program to calculate the minimum number of moves a knight requires to travel from one square to another on a chessboard. The positions a knight can move to in one step are illustrated in the figure below.

Picture 1

Input Format

The first line provides the number of knights, nn.
In the following 3n3n lines, every 33 lines describe one knight. Specifically,

  • The first line contains an integer LL indicating the size of the chessboard, which is L×LL\times L;
  • The second and third lines each contain a pair of integers (x,y)(x, y), representing the starting and ending positions of the knight. It is assumed that for each knight, the starting and ending positions are valid.

Output Format

For each knight, output one line with an integer representing the minimum number of moves required. If the starting and ending positions are the same, output 00.

Sample 1

3
8
0 0
7 0
100
0 0
30 50
10
1 1
1 1

5
28
0

Data Range and Hint

For 100%100\% of the data, 4L3004\le L\le 300, and it is guaranteed that 0x,yL10\le x,y\le L-1.