Knight takes King

1

1 votes
Easy-Medium
Problem

Ishu recently learned playing chess . Chess is fun , specially the knight's move . Ishu has been practining the Knight moves . Your task is simple , you are provided with a chessboard that has only a Knight and a King on it . You are given the coordinates of the knight and the king . Ishu wonders what would be the minimum number of moves required by the Knight to kill the King.

This chessboard is not the standard 88 chessboard . You are provided with the size of the chessboard N (N * N* dimension). The King is stationary and will not perform any move.

Direction Convention : The bottom leftmost chess square block has the coordinate (1,1) .

Input Format

The first line contains the number of test cases T .
First line of each test case contains the integer N ( denoting the size of chessboard) . Second and Third line contains two space separated integers denoting the coordinate of the Knight and the King respectively.

Output Format

For each test case output an integer in a separate line denoting the minimum number of moves required to kill the king . If it is not possible to kill the King print "-1" without quotes.

Constraint

1 <= T <= 1000
2 <= N <= 100

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?