Devu and his mouse Jerry

All submissions for this problem are available.
Read problems statements in Mandarin Chinese , Russian and Vietnamese
Devu loves to play with his dear mouse Jerry. One day they play a game on 2 dimensional grid of dimensions n * n (n ≥ 2). Jerry is currently at coordinates (s_{x}, s_{y}) and wants to move to location (e_{x}, e_{y}) where cheese is placed by Devu. Also Devu is very cunning and has placed a bomb at location (b_{x}, b_{y}). All these three locations are distinct.
In a single move, Jerry can go either up, down, left or right in the grid such that it never goes out of the grid. Also, it has to avoid the bomb. Find out minimum number of moves Jerry needs. It is guaranteed that it is always possible to do so.
Input
 The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows."
 The first line of each test case contains seven space separated integers n, s_{x}, s_{y} , e_{x}, e_{y}, b_{x}, b_{y}.
Output
 For each test case, output a single line containing an integer corresponding to minimum number of moves Jerry needs.
Constraints
 1 ≤ T ≤ 1000
 2 ≤ n ≤ 20
 1 ≤ s_{x}, s_{y} , e_{x}, e_{y}, b_{x}, b_{y} ≤ n
 No two or more poitns in the three points are same.
Example
Input: 2 2 1 1 2 2 1 2 3 1 1 1 3 1 2 Output: 2 4
Explanation
Example case 1. ...
Jerry will move directly (1, 1) to (2, 1) and then to (2, 2) in total 2 moves.Example case 2. ...
Author:  admin2 
Editorial  http://discuss.codechef.com/problems/DEVJERRY 
Tags  admin2, snck151c 
Date Added:  1062015 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 