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 (sx, sy) and wants to move to location (ex, ey) where cheese is placed by Devu. Also Devu is very cunning and has placed a bomb at location (bx, by). 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, sx, sy , ex, ey, bx, by. 

-----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 ≤ sx, sy , ex, ey, bx, by ≤ 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. ...

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
import sys

def _r(*conv):
	r = [conv[i](x) for (i, x) in enumerate(input().strip().split(' '))]
	return r[0] if len(r) == 1 else r

def _ra(conv):
	return list(map(conv, input().strip().split(' ')))

def _rl():
	return list(input().strip())

def _rs():
	return input().strip()

def _a(k, *v):
	return all((x == k for x in v))

def _i(conv):
	for line in sys.stdin:
		yield conv(line)
for _ in range(_r(int)):
	(n, sx, sy, ex, ey, bx, by) = _ra(int)
	if sx != ex and sy != ey:
		print(abs(sx - ex) + abs(sy - ey))
	elif sx == ex:
		if sx == bx:
			if by > sy and by < ey or (by < sy and by > ey):
				print(abs(sx - ex) + abs(sy - ey) + 2)
			else:
				print(abs(sx - ex) + abs(sy - ey))
		else:
			print(abs(sx - ex) + abs(sy - ey))
	elif sy == by:
		if bx > sx and bx < ex or (bx < sx and bx > ex):
			print(abs(sx - ex) + abs(sy - ey) + 2)
		else:
			print(abs(sx - ex) + abs(sy - ey))
	else:
		print(abs(sx - ex) + abs(sy - ey))


t = eval(input())
for z in range(t):
	tot = 0
	(n, sx, sy, ex, ey, bx, by) = list(map(int, input().strip().split(' ')))
	if sx == ex or sy == ey:
		if sx == ex:
			if sx == bx and (by >= min(sy, ey) and by <= max(sy, ey)):
				tot += 2
		elif sy == ey:
			if sy == by and (bx >= min(sx, ex) and bx <= max(sx, ex)):
				tot += 2
	tot += abs(sx - ex) + abs(sy - ey)
	print(tot)


for cas in range(eval(input())):
	(n, sx, sy, ex, ey, bx, by) = list(map(int, input().strip().split()))
	print(abs(sx - ex) + abs(sy - ey) + 2 * ((sx == ex or sy == ey) and min(sx, ex) <= bx <= max(sx, ex) and (min(sy, ey) <= by <= max(sy, ey))))


T = int(input())
for i in range(T):
	(n, sx, sy, ex, ey, bx, by) = list(map(int, input().split()))
	if sx != ex and sy != ey:
		a = abs(sx - ex) + abs(sy - ey)
		print(a)
	elif sx == ex:
		if ex == bx and (by - sy) * (ey - by) > 0:
			print(abs(sy - ey) + 2)
		else:
			print(abs(sy - ey))
	elif ey == by and (bx - sx) * (ex - bx) > 0:
		print(abs(sx - ex) + 2)
	else:
		print(abs(sx - ex))


import sys

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		(n, sx, sy, dx, dy, bx, by) = list(map(int, sys.stdin.readline().strip().split()))
		if sx == bx == dx and min(sy, dy) < by and (by < max(sy, dy)):
			print(abs(dx - sx) + abs(dy - sy) + 2)
		elif sy == by == dy and min(sx, dx) < bx and (bx < max(sx, dx)):
			print(abs(dx - sx) + abs(dy - sy) + 2)
		else:
			print(abs(dx - sx) + abs(dy - sy))
main()


for _ in range(eval(input())):
	a = list(map(int, input().split()))
	s = [a[1], a[2]]
	e = [a[3], a[4]]
	b = [a[5], a[6]]
	c = abs(e[1] - s[1]) + abs(e[0] - s[0])
	if b[0] == e[0] and b[1] < e[1]:
		c += 2
		print(c)
	else:
		print(c)