Targeted Bishop

4

1 votes
Problem

It is the summer of 2007 and Dev is learning chess moves. After learning some basic movements of the bishop, a question clicks in his mind and now he is curious to find out what will be the minimum number of moves required to move a bishop from one position to the desired position if there is no other chess piece on the board. Your task is to help Dev to find the answer to his question so that after some years of consistent hard work he can become a 2000+ rated player on platforms like Lichess.

You have been given a square chessboard of size N×N along with the position coordinates of the Bishop (x1,y1) and the position coordinates of the target (x2,y2).

Your task is to find out the minimum steps a bishop will take to reach the target position. If it is not possible then print 1.

Note:

  1. The Bishop is a chess piece that can moves in any direction diagonally.
  2. The First square (top left corner) of the N×N grid is white.

Input

  1. First line contains an integer T denotes the number of test cases.
  2. First line of each test case contains an integer N denotes the number of rows and numbers of columns.
  3. Second line of each test case contains 2 pairs of integers (x1,y1),(x2,y2).  Denotes coordinates of the bishop and the target respectively.

Output

Print the single integer for each test case denotes the minimum number of moves bishop required to reach the target or 1 if it is impossible.

Constraints

  • 1N106
  • 1x1,y1,x2,y2N
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?