There are three cells on an infinite 2-dimensional grid, labeled $A$, $B$, and $F$. Find the length of the shortest path from $A$ to $B$ if:

in one move you can go to any of the four adjacent cells sharing a side;

visiting the cell $F$ is forbidden (it is an obstacle).


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow. Before each test case, there is an empty line.

Each test case contains three lines. The first one contains two integers $x_A, y_A$ ($1 \le x_A, y_A \le 1000$) — coordinates of the start cell $A$. The second one contains two integers $x_B, y_B$ ($1 \le x_B, y_B \le 1000$) — coordinates of the finish cell $B$. The third one contains two integers $x_F, y_F$ ($1 \le x_F, y_F \le 1000$) — coordinates of the forbidden cell $F$. All cells are distinct.

Coordinate $x$ corresponds to the column number and coordinate $y$ corresponds to the row number (see the pictures below).


-----Output-----

Output $t$ lines. The $i$-th line should contain the answer for the $i$-th test case: the length of the shortest path from the cell $A$ to the cell $B$ if the cell $F$ is not allowed to be visited.


-----Examples-----

Input
7

1 1
3 3
2 2

2 5
2 1
2 3

1000 42
1000 1
1000 1000

1 10
3 10
2 10

3 8
7 8
3 7

2 1
4 1
1 1

1 344
1 10
1 1
Output
4
6
41
4
4
2
334


-----Note-----

An example of a possible shortest path for the first test case.

An example of a possible shortest path for the second test case.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation


Solutions:
t = int(input())
a = []
for i in range(t):
	blank = list(map(str, input().split()))
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	f = list(map(int, input().split()))
	if x[0] == y[0] and x[0] == f[0]:
		if (f[1] - x[1]) * (f[1] - y[1]) < 0:
			n = abs(y[1] - x[1]) + 2
		else:
			n = abs(y[1] - x[1])
	elif x[1] == y[1] and x[1] == f[1]:
		if (f[0] - x[0]) * (f[0] - y[0]) < 0:
			n = abs(y[0] - x[0]) + 2
		else:
			n = abs(y[0] - x[0])
	else:
		n = abs(y[0] - x[0]) + abs(y[1] - x[1])
	a.append(n)
for i in range(t):
	print(a[i])


def pro(A, B, F):
	(x, y) = A
	(p, q) = F
	(x1, y1) = B
	ans = 0
	if y == q == B[1] and min(x, x1) < p < max(x1, x):
		y += 1
		ans += 1
	elif x == p == x1 and min(y, y1) < q < max(y1, y):
		x += 1
		ans += 1
	ans += abs(x - x1) + abs(y - y1)
	print(ans)
t = int(input())
for i in range(t):
	input()
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	F = list(map(int, input().split()))
	pro(A, B, F)


t = int(input())
nothing = ''
for _ in range(0, t):
	nothing = input()
	xa = xb = xf = ya = yb = yf = 0
	(xa, ya) = input().split()
	(xb, yb) = input().split()
	(xf, yf) = input().split()
	(xa, xb, xf, ya, yb, yf) = (int(xa), int(xb), int(xf), int(ya), int(yb), int(yf))
	diffx = xa - xb
	diffy = ya - yb
	if diffx < 0:
		diffx = -diffx
	if diffy < 0:
		diffy = -diffy
	result = diffx + diffy
	if xa == xb == xf:
		if ya <= yf <= yb or ya >= yf >= yb:
			result += 2
	elif ya == yb == yf:
		if xa <= xf <= xb or xa >= xf >= xb:
			result += 2
	print(result)


t = int(input())
for _ in range(t):
	i = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	if xa == xb == xf and min(ya, yb) < yf < max(ya, yb):
		ans = abs(ya - yb) + 2
	elif ya == yb == yf and min(xa, xb) < xf < max(xa, xb):
		ans = abs(xa - xb) + 2
	else:
		ans = abs(xa - xb) + abs(ya - yb)
	print(ans)


import sys
input = sys.stdin.readline
T = int(input())
input()
for _ in range(T):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	answer = -1
	temp = 0
	if xa == xb == xf:
		if ya < yf < yb or yb < yf < ya:
			temp = 2
	elif ya == yb == yf:
		if xa < xf < xb or xb < xf < xa:
			temp = 2
	answer = temp + abs(xa - xb) + abs(ya - yb)
	print(answer)
	input()


for t in range(int(input())):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	res = abs(xa - xb) + abs(ya - yb)
	if xa == xb == xf:
		if yf in range(min(ya, yb), max(ya, yb)):
			res += 2
	if ya == yb == yf:
		if xf in range(min(xa, xb), max(xa, xb)):
			res += 2
	print(res)


n = int(input())
for i in range(n):
	input()
	(ax, ay) = [int(i) for i in input().split()]
	(bx, by) = [int(i) for i in input().split()]
	(fx, fy) = [int(i) for i in input().split()]
	ans = abs(ax - bx) + abs(ay - by)
	if ax == bx and ax == fx:
		if min(ay, by) < fy and fy < max(ay, by):
			ans += 2
	elif ay == by and ay == fy:
		if min(ax, bx) < fx and fx < max(ax, bx):
			ans += 2
	print(ans)


from math import *

def sol(A, B, F):
	if A[0] == B[0]:
		if min(A[1], B[1]) < F[1] < max(A[1], B[1]) and F[0] == A[0]:
			print(abs(A[1] - B[1]) + abs(A[0] - B[0]) + 2)
		else:
			print(abs(A[1] - B[1]) + abs(A[0] - B[0]))
	elif A[1] == B[1]:
		if min(A[0], B[0]) < F[0] < max(A[0], B[0]) and F[1] == A[1]:
			print(abs(A[1] - B[1]) + abs(A[0] - B[0]) + 2)
		else:
			print(abs(A[1] - B[1]) + abs(A[0] - B[0]))
	else:
		print(abs(A[1] - B[1]) + abs(A[0] - B[0]))

def main():
	for _ in range(int(input())):
		x = input()
		A = list(map(int, input().split()))
		B = list(map(int, input().split()))
		F = list(map(int, input().split()))
		sol(A, B, F)
main()


for r in range(int(input())):
	input()
	(xa, ya) = list(map(int, input().split()))
	(xb, yb) = list(map(int, input().split()))
	(xf, yf) = list(map(int, input().split()))
	if xa == xb:
		if (ya < yf < yb or ya > yf > yb) and xa == xf:
			print(abs(yb - ya) + 2)
		else:
			print(abs(yb - ya))
	elif ya == yb:
		if (xa < xf < xb or xa > xf > xb) and ya == yf:
			print(abs(xb - xa) + 2)
		else:
			print(abs(xb - xa))
	else:
		print(abs(xb - xa) + abs(yb - ya))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	ans = abs(xa - xb) + abs(ya - yb)
	tmp = 0
	if xa == xb == xf and (yf - ya) * (yf - yb) < 0:
		tmp = 2
	if ya == yb == yf and (xf - xa) * (xf - xb) < 0:
		tmp = 2
	print(ans + tmp)


n = int(input())
for i in range(n):
	x_A = 0
	x_B = 0
	y_A = 0
	y_B = 0
	x_F = 0
	y_F = 0
	s = input()
	s = input().split()
	x_A = int(s[0])
	y_A = int(s[1])
	s = input().split()
	x_B = int(s[0])
	y_B = int(s[1])
	s = input().split()
	x_F = int(s[0])
	y_F = int(s[1])
	if x_A == x_B == x_F and (y_A > y_F > y_B or y_B > y_F > y_A):
		print(abs(y_A - y_B) + 2)
	elif y_A == y_B == y_F and (x_A > x_F > x_B or x_B > x_F > x_A):
		print(abs(x_A - x_B) + 2)
	else:
		print(abs(x_A - x_B) + abs(y_A - y_B))


for t in range(int(input())):
	s = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	if x1 == x3 and y1 == y3 or (x2 == x3 and y2 == y3):
		print(-1)
		continue
	elif x1 == x2 and y1 == y2:
		print(0)
	elif x1 == x2:
		val = abs(y2 - y1)
		if x3 == x1 and y3 > min(y2, y1) and (y3 < max(y2, y1)):
			val += 2
		print(val)
		continue
	elif y1 == y2:
		val = abs(x1 - x2)
		if y3 == y1 and x3 > min(x1, x2) and (x3 < max(x1, x2)):
			val += 2
		print(val)
		continue
	else:
		print(abs(x1 - x2) + abs(y1 - y2))


for _ in range(int(input())):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	if ya == yb == yf and (xa < xf) != (xb < xf) or (xa == xb == xf and (ya < yf) != (yb < yf)):
		print(2 + abs(xa - xb) + abs(ya - yb))
	else:
		print(abs(xa - xb) + abs(ya - yb))


res = []
tests = int(input())
for j in range(tests):
	a = input().split()
	b = input().split()
	c = input().split()
	d = input().split()
	(a1, a2, b1, b2, f1, f2) = (int(b[0]), int(b[1]), int(c[0]), int(c[1]), int(d[0]), int(d[1]))
	if a1 == b1 == f1 and f2 != min(a2, b2, f2) and (f2 != max(a2, b2, f2)):
		res.append(abs(a2 - b2) + 2)
	elif a2 == b2 == f2 and f1 != min(a1, b1, f1) and (f1 != max(a1, b1, f1)):
		res.append(abs(a1 - b1) + 2)
	else:
		res.append(abs(a1 - b1) + abs(a2 - b2))
for i in res:
	print(i)


from sys import stdin, stdout

def solve(ax, ay, bx, by, fx, fy):
	rx = abs(ax - bx)
	ry = abs(ay - by)
	if ax == bx or ay == by:
		e = 0
		if fx in range(min(ax, bx), max(ax, bx) + 1):
			if fy == ay:
				e += 2
		if fy in range(min(ay, by), max(ay, by) + 1):
			if fx == ax:
				e += 2
		return rx + ry + e
	return rx + ry
t = int(input())
for _ in range(t):
	blank = input()
	if blank != '':
		break
	(ax, ay) = [int(c) for c in input().split()]
	(bx, by) = [int(c) for c in input().split()]
	(fx, fy) = [int(c) for c in input().split()]
	print(solve(ax, ay, bx, by, fx, fy))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	input()
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(cx, cy) = map(int, input().split())
	res = abs(ax - bx) + abs(ay - by)
	if ax == bx == cx and cy in range(min(ay, by), max(ay, by)):
		res += 2
	if ay == by == cy and cx in range(min(ax, bx), max(ax, bx)):
		res += 2
	print(res)


for _ in range(int(input())):
	input()
	(x_a, y_a) = input().split()
	(x_a, y_a) = (int(x_a), int(y_a))
	(x_b, y_b) = input().split()
	(x_b, y_b) = (int(x_b), int(y_b))
	(x_f, y_f) = input().split()
	(x_f, y_f) = (int(x_f), int(y_f))
	answer = abs(x_a - x_b) + abs(y_a - y_b)
	if x_a == x_b == x_f and min(y_a, y_b) < y_f < max(y_a, y_b) or (y_a == y_b == y_f and min(x_a, x_b) < x_f < max(x_a, x_b)):
		answer += 2
	print(answer)


t = int(input())
A = []
for zxc_ghoul in range(t):
	none = input()
	(x_a, y_a) = map(int, input().split())
	(x_b, y_b) = map(int, input().split())
	(x_f, y_f) = map(int, input().split())
	if x_a == x_b or y_a == y_b:
		if x_a == x_b:
			if x_a == x_f and (y_a > y_f and y_f > y_b or (y_f > y_a and y_f < y_b)):
				ans = abs(y_a - y_b) + 2
			else:
				ans = abs(y_a - y_b)
		if y_a == y_b:
			if y_a == y_f and (x_a > x_f and x_f > x_b or (x_f > x_a and x_f < x_b)):
				ans = abs(x_a - x_b) + 2
			else:
				ans = abs(x_a - x_b)
	else:
		ans = abs(x_a - x_b) + abs(y_a - y_b)
	A.append(ans)
for i in A:
	print(i)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def solve():
	a = readstr()
	(ax, ay) = readints()
	(cx, cy) = readints()
	(bx, by) = readints()
	manhattan = abs(ax - cx) + abs(ay - cy)
	if ay == cy or ax == cx:
		if ax == cx == bx and (ay <= by <= cy or ay >= by >= cy) or (ay == cy == by and (ax <= bx <= cx or ax >= bx >= cx)):
			manhattan += 2
	print(manhattan)

def main():
	t = 1
	t = readint()
	for _ in range(t):
		solve()
main()


import os
import sys
from math import ceil, floor, sqrt, gcd, factorial
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	for _ in range(int(input())):
		input()
		(xa, ya) = map(int, input().split())
		(xb, yb) = map(int, input().split())
		(xf, yf) = map(int, input().split())
		if xa == xb == xf and yf < max(yb, ya) and (yf > min(yb, ya)):
			print(abs(xb - xa) + abs(yb - ya) + 2)
		elif ya == yb == yf and xf < max(xb, xa) and (xf > min(xb, xa)):
			print(abs(xb - xa) + abs(yb - ya) + 2)
		else:
			print(abs(xb - xa) + abs(yb - ya))
main()


t = int(input())
p = 0
while p < t:
	input()
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(fx, fy) = map(int, input().split())
	if ay == by == fy and (ax > fx > bx or ax < fx < bx):
		print(abs(ax - bx) + 2)
	elif ax == bx == fx and (ay > fy > by or ay < fy < by):
		print(abs(ay - by) + 2)
	else:
		print(abs(ax - bx) + abs(ay - by))
	p += 1


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

def SieveOfEratosthenes(n=10000):
	p = 2
	c = 0
	while p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				prime[i] = False
		p += 1

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[n - 1]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = arr[mid]
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][0] >= key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
t = 1
t = int(input())
for _ in range(t):
	x = input()
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	dist = abs(a - c) + abs(b - d)
	if a == c == e and f > min(b, d) and (f < max(b, d)):
		dist += 2
	elif b == d == f and e > min(a, c) and (e < max(a, c)):
		dist += 2
	print(dist)


t = int(input())
for _ in range(t):
	_ = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	ans = abs(xb - xa) + abs(yb - ya)
	if xa == xb and xb == xf:
		if yf > ya and yf < yb or (yf > yb and yf < ya):
			ans += 2
	elif ya == yb and yb == yf:
		if xf > xa and xf < xb or (xf > xb and xf < xa):
			ans += 2
	print(ans)


l = ''.join([*open(0)]).split('\n\n')[1:]
for i in l:
	(a, b, c, d, e, f) = map(int, i.split())
	n = abs(a - c) + abs(b - d)
	if a == c == e and b < f < d or (a == c == e and d < f < b) or (b == d == f and a < e < c) or (b == d == f and c < e < a):
		print(n + 2)
	else:
		print(n)


a = int(input())
mas = []
for i in range(a):
	input()
	mass = []
	mass.append(input().split())
	mass[0][0] = int(mass[0][0])
	mass[0][1] = int(mass[0][1])
	mass.append(input().split())
	mass[1][0] = int(mass[1][0])
	mass[1][1] = int(mass[1][1])
	mass.append(input().split())
	mass[2][0] = int(mass[2][0])
	mass[2][1] = int(mass[2][1])
	mas.append(mass)
for i in mas:
	lex = abs(i[0][0] - i[1][0])
	ley = abs(i[0][1] - i[1][1])
	le = lex + ley
	if lex == 0 and i[2][0] == i[0][0] and (i[2][1] > min(i[0][1], i[1][1])) and (i[2][1] < max(i[0][1], i[1][1])):
		le += 2
	if ley == 0 and i[2][1] == i[0][1] and (i[2][0] > min(i[0][0], i[1][0])) and (i[2][0] < max(i[0][0], i[1][0])):
		le += 2
	print(le)


t = int(input())
anslist = []
for i in range(t):
	inp = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(f1, f2) = map(int, input().split())
	if x1 != x2 and y1 != y2:
		anslist.append(abs(x2 - x1) + abs(y2 - y1))
	elif x1 == x2:
		if f1 == x1:
			if f2 > y1 and f2 < y2:
				anslist.append(abs(y2 - y1) + 2)
			elif f2 < y1 and f2 > y2:
				anslist.append(abs(y2 - y1) + 2)
			else:
				anslist.append(abs(y2 - y1))
		else:
			anslist.append(abs(y2 - y1))
	elif y1 == y2:
		if f2 == y1:
			if f1 > x1 and f1 < x2:
				anslist.append(abs(x2 - x1) + 2)
				pass
			elif f1 < x1 and f1 > x2:
				anslist.append(abs(x2 - x1) + 2)
			else:
				anslist.append(abs(x2 - x1))
		else:
			anslist.append(abs(x2 - x1))
length = len(anslist)
y = 0
for i in range(length):
	print(anslist[y])
	y += 1


import sys
import collections
import bisect
import time
import random
from itertools import permutations
import string
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
tc = int(input())
input()
for t in range(tc):
	(x1, y1) = get_ints()
	(x2, y2) = get_ints()
	(x3, y3) = get_ints()
	if t != tc - 1:
		input()
	ans = abs(x1 - x2) + abs(y1 - y2)
	minimy = min(y1, y2)
	maximy = max(y1, y2)
	minimx = min(x1, x2)
	maximx = max(x1, x2)
	if x1 == x2 == x3:
		if y3 >= minimy and y3 <= maximy:
			ans += 2
	elif y1 == y2 == y3:
		if x3 >= minimx and x3 <= maximx:
			ans += 2
	print(ans)


import os, sys, time, collections, math, pprint, itertools as it, operator as op, bisect as bs, functools as fn
(maxx, localsys, mod) = (1 << 60, 0, int(1000000000.0 + 7))
nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)
ceil = lambda n, x: (n + x - 1) // x
(osi, oso) = ('/home/priyanshu/Documents/cp/input.txt', '/home/priyanshu/Documents/cp/output.txt')
if os.path.exists(osi):
	sys.stdin = open(osi, 'r')
	sys.stdout = open(oso, 'w')
input = sys.stdin.readline

def maps():
	return map(int, input().split())
for _ in range(int(input())):
	for i in range(4):
		if i == 0:
			input()
		if i == 1:
			(ax, ay) = list(maps())
		if i == 2:
			(bx, by) = list(maps())
		if i == 3:
			(fx, fy) = list(maps())
	dis = abs(ax - bx) + abs(ay - by)
	if ax == bx == fx and fy >= min(ay, by) and (fy <= max(ay, by)):
		print(dis + 2)
	elif ay == by == fy and fx >= min(ax, bx) and (fx <= max(ax, bx)):
		print(dis + 2)
	else:
		print(dis)


import math
from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd
import bisect
import sys
import random
import heapq

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
for _ in range(int(input())):
	_ = input()
	(xa, ya) = get_ints()
	(xb, yb) = get_ints()
	(xc, yc) = get_ints()
	if xa == xb == xc and (ya > yc and yb < yc or (ya < yc and yb > yc)) or (ya == yb == yc and (xa > xc and xb < xc or (xa < xc and xb > xc))):
		print(abs(xb - xa) + abs(yb - ya) + 2)
	else:
		print(abs(xb - xa) + abs(yb - ya))


t = int(input())

def is_between(a, b, f):
	mx = max(a, b)
	mn = min(a, b)
	if mn < f and f < mx:
		return True
	else:
		return False
for _t in range(t):
	input()
	(xa, ya) = list(map(int, input().split()))
	(xb, yb) = list(map(int, input().split()))
	(xf, yf) = list(map(int, input().split()))
	if xa == xb:
		if xa == xf and is_between(ya, yb, yf):
			print(abs(yb - ya) + 2)
		else:
			print(abs(yb - ya))
	elif ya == yb:
		if ya == yf and is_between(xa, xb, xf):
			print(abs(xb - xa) + 2)
		else:
			print(abs(xb - xa))
	else:
		print(abs(xa - xb) + abs(ya - yb))


from sys import stdin, setrecursionlimit
from collections import defaultdict
setrecursionlimit(10 ** 7)
for _ in range(int(stdin.readline())):
	x = stdin.readline()
	(ax, ay) = map(int, stdin.readline().split())
	(bx, by) = map(int, stdin.readline().split())
	(fx, fy) = map(int, stdin.readline().split())
	if (fx == ax == bx or fy == ay == by) and (ax < fx < bx or ax > fx > bx or ay < fy < by or (ay > fy > by)):
		print(abs(ax - bx) + abs(ay - by) + 2)
	else:
		print(abs(ax - bx) + abs(ay - by))


for s in ''.join(open(0)).split('\n\n')[1:]:
	(a, b, c, d, e, f) = map(int, s.split())
	print(abs(a - c) + abs(b - d) + 2 * (a == c == e and (b < f < d or d < f < b) or (b == d == f and (a < e < c or c < e < a))))


import sys, math
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def li():
	return list(map(int, input().split()))
t = int(input())
a = []
for _ in range(t):
	input()
	(sx, sy) = li()
	(tx, ty) = li()
	(fx, fy) = li()
	ans = abs(sx - tx) + abs(sy - ty)
	if sx == tx == fx and (sy < fy < ty or ty < fy < sy):
		ans += 2
	elif sy == ty == fy and (sx < fx < tx or tx < fx < sx):
		ans += 2
	a.append(ans)
for ans in a:
	print(ans)


t = int(input())
for i in range(t):
	temp = input()
	(Xa, Ya) = [int(x) for x in input().split()]
	(Xb, Yb) = [int(x) for x in input().split()]
	(Xc, Yc) = [int(x) for x in input().split()]
	if Xa == Xb == Xc and Yc < max(Ya, Yb) and (Yc > min(Ya, Yb)) or (Ya == Yb == Yc and Xc < max(Xa, Xb) and (Xc > min(Xa, Xb))):
		result = abs(Xa - Xb) + abs(Ya - Yb) + 2
	else:
		result = abs(Xa - Xb) + abs(Ya - Yb)
	print(result)


t = int(input())
for i in range(t):
	input()
	(xa, ya) = list(map(int, input().split()))
	(xb, yb) = list(map(int, input().split()))
	(xf, yf) = list(map(int, input().split()))
	ans = 0
	if xa == xb:
		if xf != xb:
			ans = abs(ya - yb)
		elif yf < min(ya, yb) or yf > max(ya, yb):
			ans = abs(ya - yb)
		else:
			ans = abs(ya - yb) + 2
	elif ya == yb:
		if yf != yb:
			ans = abs(xa - xb)
		elif xf < min(xa, xb) or xf > max(xa, xb):
			ans = abs(xa - xb)
		else:
			ans = abs(xa - xb) + 2
	else:
		ans = abs(ya - yb) + abs(xa - xb)
	print(ans)


from collections import deque, defaultdict, Counter, OrderedDict
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
from math import sqrt
import collections
import math
import heapq
import re
from statistics import mode

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r):
	return fact[n] * pow(fact[r] * fact[n - r], mod - 2, mod) % mod

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(inin()):
		lol = input()
		(x1, y1) = map(int, input().split())
		(x2, y2) = map(int, input().split())
		(x3, y3) = map(int, input().split())
		if x1 == x2 and x2 == x3 and (y3 > min(y1, y2)) and (y3 < max(y1, y2)):
			print(abs(y2 - y1) + abs(x2 - x1) + 2)
		elif y1 == y2 and y2 == y3 and (x3 > min(x1, x2)) and (x3 < max(x2, x1)):
			print(abs(y2 - y1) + abs(x2 - x1) + 2)
		else:
			print(abs(y2 - y1) + abs(x2 - x1))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys

def get_string():
	return sys.stdin.readline().strip()

def get_array():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def get_num():
	return int(sys.stdin.readline())
t = get_num()
for i in range(t):
	a = []
	for j in range(4):
		x = get_array()
		if j > 0:
			a.append(x)
	distance = abs(a[0][0] - a[1][0]) + abs(a[0][1] - a[1][1])
	if a[0][0] == a[1][0] == a[2][0] and a[0][1] < a[2][1] < a[1][1]:
		distance += 2
	elif a[0][1] == a[1][1] == a[2][1] and a[0][0] < a[2][0] < a[1][0]:
		distance += 2
	elif a[0][0] == a[1][0] == a[2][0] and a[0][1] > a[2][1] > a[1][1]:
		distance += 2
	elif a[0][1] == a[1][1] == a[2][1] and a[0][0] > a[2][0] > a[1][0]:
		distance += 2
	print(distance)


def is_f_aligned(xA, yA, xB, yB, xF, yF):
	flag = False
	if xF == xA and xF == xB:
		if yF > min(yA, yB) and yF < max(yA, yB):
			flag = True
	if yF == yA and yF == yB:
		if xF > min(xA, xB) and xF < max(xA, xB):
			flag = True
	return flag
t = int(input())
for i in range(t):
	blank = input()
	pA = input()
	pB = input()
	pF = input()
	pA = list(map(int, pA.split(' ')))
	pB = list(map(int, pB.split(' ')))
	pF = list(map(int, pF.split(' ')))
	formula = lambda xA, yA, xB, yB: abs(xA - xB) + abs(yA - yB)
	xA = pA[0]
	yA = pA[1]
	xB = pB[0]
	yB = pB[1]
	xF = pF[0]
	yF = pF[1]
	steps = formula(xA, yA, xB, yB)
	if is_f_aligned(xA, yA, xB, yB, xF, yF) == True:
		print(steps + 2)
	else:
		print(steps)


t = int(input())
for _ in range(t):
	o = input()
	(a1, b1) = [int(i) for i in input().split()]
	(a2, b2) = [int(i) for i in input().split()]
	(a3, b3) = [int(i) for i in input().split()]
	if a1 != a2 and b1 != b2:
		print(abs(a1 - a2) + abs(b1 - b2))
	elif a1 == a2 == a3 and (b3 > b1 and b3 < b2 or (b3 > b2 and b3 < b1)):
		print(abs(a1 - a2) + abs(b1 - b2) + 2)
	elif b1 == b2 == b3 and (a3 > a1 and a3 < a2 or (a3 > a2 and a3 < a1)):
		print(abs(a1 - a2) + abs(b1 - b2) + 2)
	else:
		print(abs(a1 - a2) + abs(b1 - b2))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	sys.stdin.readline()
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	f = list(map(int, sys.stdin.readline().split()))
	answer = abs(a[0] - b[0]) + abs(a[1] - b[1])
	if a[0] == b[0] == f[0]:
		if (a[1] - f[1]) * (b[1] - f[1]) < 0:
			answer += 2
	elif a[1] == b[1] == f[1]:
		if (a[0] - f[0]) * (b[0] - f[0]) < 0:
			answer += 2
	print(answer)


for i in range(int(input())):
	input()
	(ax, ay) = [int(x) for x in input().split()]
	(bx, by) = [int(x) for x in input().split()]
	(fx, fy) = [int(x) for x in input().split()]
	if ax == bx == fx and fy > min(ay, by) and (fy < max(by, ay)):
		print(abs(bx - ax) + abs(by - ay) + 2)
	elif ay == by == fy and fx > min(ax, bx) and (fx < max(ax, bx)):
		print(abs(bx - ax) + abs(by - ay) + 2)
	else:
		print(abs(bx - ax) + abs(by - ay))


n = int(input())
for _ in range(n):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = list(map(int, input().split()))
	if a[0] == b[0]:
		d = abs(a[1] - b[1])
		if f[0] == a[0]:
			if abs(a[1] - f[1]) + abs(b[1] - f[1]) == abs(a[1] - b[1]):
				d += 2
	elif a[1] == b[1]:
		d = abs(a[0] - b[0])
		if f[1] == a[1]:
			if abs(a[0] - f[0]) + abs(b[0] - f[0]) == abs(a[0] - b[0]):
				d += 2
	else:
		d = abs(a[0] - b[0]) + abs(a[1] - b[1])
	print(d)


T = int(input())
for _ in range(T):
	input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(cx, cy) = map(int, input().split())
	d1 = abs(x1 - cx) + abs(y1 - cy)
	d2 = abs(x2 - cx) + abs(y2 - cy)
	d3 = abs(x2 - x1) + abs(y2 - y1)
	if (x1 == x2 == cx or y1 == y2 == cy) and d1 + d2 == d3:
		print(d3 + 2)
	else:
		print(d3)


for i in range(int(input())):
	x = input()
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	if a != c and b != d:
		print(abs(a - c) + abs(b - d))
	elif a == c and b != d:
		if a == e and (f > b and f < d or (f < b and f > d)):
			print(abs(b - d) + 2)
		else:
			print(abs(b - d))
	elif a != c and b == d:
		if b == f and (e > a and e < c or (e < a and e > c)):
			print(abs(a - c) + 2)
		else:
			print(abs(a - c))
	else:
		print(0)


import sys
import math
import os.path
from collections import *
from queue import *
from bisect import *
from heapq import *
MOD = int(1000000000.0 + 7)
inf = float('inf')
ninf = float('-inf')
input = sys.stdin.buffer.readline

def ii():
	return list(map(int, input().strip().split()))

def deb(a, b='Debugging'):
	print(b, *a) if os.path.exists('inp.txt') else ''
for _ in range(int(input())):
	p = input()
	(a1, a2) = ii()
	(b1, b2) = ii()
	(f1, f2) = ii()
	if a1 == b1 and a1 == f1 and (a2 <= f2 <= b2 or b2 <= f2 <= a2):
		print(abs(a2 - b2) + 2)
	elif a2 == b2 and a2 == f2 and (a1 <= f1 <= b1 or b1 <= f1 <= a1):
		print(abs(a1 - b1) + 2)
	else:
		print(abs(a1 - b1) + abs(a2 - b2))


t = int(input())
for _ in range(t):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	q1 = abs(xa - xb)
	q2 = abs(ya - yb)
	if q1 >= 1 and q2 >= 1:
		print(q1 + q2)
	elif q2 < 1:
		if yf == ya and (xf > xa and xf < xb or (xf < xa and xf > xb)):
			print(q1 + q2 + 2)
		else:
			print(q1 + q2)
	elif xf == xa and (yf > ya and yf < yb or (yf < ya and yf > yb)):
		print(q1 + q2 + 2)
	else:
		print(q1 + q2)


for i in range(int(input())):
	z = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	if xa == ya and xb == yb:
		print(abs(xa - xb) + abs(ya - yb))
		continue
	elif (xa == xb == xf or ya == yb == yf) and (xa < xf < xb or ya < yf < yb or xa > xf > xb or (ya > yf > yb)):
		print(abs(xa - xb) + abs(ya - yb) + 2)
		continue
	else:
		print(abs(xa - xb) + abs(ya - yb))
		continue


import sys
t = int(sys.stdin.readline())

def sol(st, ed, forbid):
	(xs, ys) = (st[0], st[1])
	(xe, ye) = (ed[0], ed[1])
	(xf, yf) = (forbid[0], forbid[1])
	if xs == xe and ys == ye:
		return 0
	if xs == xe and xe == xf and (min(ys, ye) < yf) and (yf < max(ys, ye)) or (ys == ye and ye == yf and (min(xs, xe) < xf) and (xf < max(xs, xe))):
		return 2 + abs(xe - xs) + abs(ye - ys)
	else:
		return abs(xe - xs) + abs(ye - ys)
for i in range(t):
	cells = []
	a = sys.stdin.readline()
	st = list(map(int, sys.stdin.readline().split()))
	ed = list(map(int, sys.stdin.readline().split()))
	forb = list(map(int, sys.stdin.readline().split()))
	print(sol(st, ed, forb))


import sys
input = sys.stdin.readline

def read():
	return map(int, input().split())

def readarr():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	void = input()
	(ax, ay) = read()
	(bx, by) = read()
	(fx, fy) = read()
	ans = abs(bx - ax) + abs(by - ay)
	if ax == bx or ay == by:
		if min(ax, bx) <= fx <= max(ax, bx) and min(ay, by) <= fy <= max(ay, by):
			ans += 2
	print(ans)


t = int(input())
for i in range(t):
	input()
	(a_x, a_y) = map(int, input().split())
	(b_x, b_y) = map(int, input().split())
	(f_x, f_y) = map(int, input().split())
	count = 0
	count += abs(b_x - a_x)
	count += abs(b_y - a_y)
	if b_x == f_x == a_x and (a_y < f_y < b_y or a_y > f_y > b_y) or (b_y == f_y == a_y and (a_x < f_x < b_x or a_x > f_x > b_x)):
		count += 2
	print(count)


for _ in range(int(input())):
	p = input()
	(a, b) = map(int, input().split())
	(x, y) = map(int, input().split())
	(fa, fb) = map(int, input().split())
	ans = abs(x - a) + abs(y - b)
	if a == x and x == fa and (fb > min(b, y)) and (fb < max(b, y)) or (b == y and y == fb and (fa < max(a, x)) and (fa > min(a, x))):
		ans += 2
	print(ans)


import sys, math
input = sys.stdin.readline
for _ in range(int(input())):
	s = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	if x1 != x2 and y1 != y2:
		print(abs(x1 - x2) + abs(y1 - y2))
	elif x1 == x2 and x2 == x3:
		if y1 < y3 and y3 < y2 or (y3 < y1 and y3 > y2):
			print(abs(x1 - x2) + abs(y1 - y2) + 2)
		else:
			print(abs(x1 - x2) + abs(y1 - y2))
	elif y1 == y2 and y2 == y3:
		if x1 < x3 and x3 < x2 or (x3 < x1 and x3 > x2):
			print(abs(x1 - x2) + abs(y1 - y2) + 2)
		else:
			print(abs(x1 - x2) + abs(y1 - y2))
	else:
		print(abs(x1 - x2) + abs(y1 - y2))


for _ in range(0, int(input())):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	d = abs(a[0] - b[0]) + abs(a[1] - b[1])
	(n, m) = sorted([a[1], b[1]])
	f = a[0] == b[0] and b[0] == c[0] and (c[1] > n) and (c[1] < m)
	(n, m) = sorted([a[0], b[0]])
	f = f or (a[1] == b[1] and b[1] == c[1] and (c[0] > n) and (c[0] < m))
	print(d + [0, 2][f])


for _ in range(int(input())):
	g = input()
	(ax, ay) = [int(x) for x in input().split()]
	(bx, by) = [int(x) for x in input().split()]
	(fx, fy) = [int(x) for x in input().split()]
	if ax == bx == fx and (ay < fy < by or ay > fy > by) or (ay == by == fy and (ax < fx < bx or ax > fx > bx)):
		print(abs(bx - ax) + abs(ay - by) + 2)
	else:
		print(abs(bx - ax) + abs(ay - by))


n = int(input())
for xx in range(n):
	_ = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	if xa == xb:
		if xf == xa and (ya <= yf <= yb or yb <= yf <= ya):
			wyn = abs(ya - yb) + 2
		else:
			wyn = abs(ya - yb)
	elif ya == yb:
		if yf == ya and (xa <= xf <= xb or xb <= xf <= xa):
			wyn = abs(xa - xb) + 2
		else:
			wyn = abs(xa - xb)
	else:
		wyn = abs(xa - xb) + abs(ya - yb)
	print(wyn)


import math
num = int(input())
while num > 0:
	a = input()
	if a == '':
		a = input().split(' ')
	else:
		a = a.split(' ')
	b = input().split(' ')
	c = input().split(' ')
	a1 = int(a[0])
	a2 = int(a[1])
	b1 = int(b[0])
	b2 = int(b[1])
	c1 = int(c[0])
	c2 = int(c[1])
	if a1 == b1 and a1 == c1:
		y = int(math.fabs(b2 - a2) + 2) if c2 < a2 and c2 > b2 or (c2 < b2 and c2 > a2) else int(math.fabs(b2 - a2))
		print(y)
	elif a2 == b2 and a2 == c2:
		y = int(math.fabs(b1 - a1) + 2) if c1 < a1 and c1 > b1 or (c1 < b1 and c1 > a1) else int(math.fabs(b1 - a1))
		print(y)
	else:
		y = int(math.fabs(b2 - a2) + math.fabs(b1 - a1))
		print(y)
	num = num - 1


def shortestpath(xa, ya, xb, yb, xf, yf):
	if xa == xb and ya == yb:
		return 0
	if xa == xb and xa == xf:
		if ya < yb:
			if yf > ya and yf < yb:
				return abs(yb - ya) + 2
			else:
				return abs(yb - ya)
		elif yf > yb and yf < ya:
			return abs(yb - ya) + 2
		else:
			return abs(yb - ya)
	elif ya == yb and ya == yf:
		if xa > xb:
			if xf > xb and xf < xa:
				return abs(xb - xa) + 2
			else:
				return abs(xb - xa)
		elif xf > xa and xf < xb:
			return abs(xb - xa) + 2
		else:
			return abs(xb - xa)
	else:
		return abs(xb - xa) + abs(yb - ya)
for _ in range(int(input())):
	empty = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	print(shortestpath(xa, ya, xb, yb, xf, yf))


t = int(input())
for i in range(0, t):
	q = input()
	(a1, b1) = map(int, input().split())
	(a2, b2) = map(int, input().split())
	(a3, b3) = map(int, input().split())
	if (b1 == b3 and b1 == b2) and (a3 < a1 and a3 > a2 or (a3 > a1 and a3 < a2)):
		print(abs(a2 - a1) + abs(b2 - b1) + 2)
	elif (a1 == a2 and a1 == a3) and (b3 < b1 and b3 > b2 or (b3 > b1 and b3 < b2)):
		print(abs(a2 - a1) + abs(b2 - b1) + 2)
	else:
		print(abs(a2 - a1) + abs(b2 - b1))


import math, sys, itertools
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in [wtf[i:i + 4] for i in range(1, len(wtf), 4)]:
	A = [list(map(int, a.split())) for a in t[1:]]
	dy = A[1][1] - A[0][1]
	dx = A[1][0] - A[0][0]
	ans = abs(dy) + abs(dx)
	(dxp, dyp) = (0, 0)
	if dy == 0 and A[0][1] == A[2][1]:
		dxp = A[0][0] - A[2][0]
		dyp = A[1][0] - A[2][0]
	if dx == 0 and A[0][0] == A[2][0]:
		dxp = A[0][1] - A[2][1]
		dyp = A[1][1] - A[2][1]
	if dxp > 0 and dyp < 0 or (dyp > 0 and dxp < 0):
		ans += 2
	print(ans)


def main():
	import sys
	input = sys.stdin.readline
	M = int(1000000000.0 + 7)
	for _ in range(int(input())):
		input()
		(xa, ya) = map(int, input().split())
		(xb, yb) = map(int, input().split())
		(xf, yf) = map(int, input().split())
		ans = abs(xa - xb) + abs(ya - yb)
		if xa == xb and xb == xf:
			if min(ya, yb) < yf < max(ya, yb):
				ans += 2
			else:
				ans += 0
		elif ya == yb and yb == yf:
			if min(xa, xb) < xf < max(xa, xb):
				ans += 2
			else:
				ans += 0
		else:
			ans += 0
		print(ans)
main()


def proof(xm, ym, xf, yf, xs, ys):
	if xm == xf and xf == xs and (ys > min(ym, yf)) and (ys < max(ym, yf)):
		anz = max(ym, yf) - min(ym, yf) + 2
	elif ym == yf and yf == ys and (xs > min(xm, xf)) and (xs < max(xm, xf)):
		anz = max(xm, xf) - min(xm, xf) + 2
	else:
		anz = max(ym, yf) - min(ym, yf) + (max(xm, xf) - min(xm, xf))
	return anz
a = int(input())
ans = []
for i in range(a):
	z = str(input())
	(xm, ym) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	(xs, ys) = map(int, input().split())
	ans.append(proof(xm, ym, xf, yf, xs, ys))
for i in range(len(ans)):
	print(ans[i])


import math
for t in range(int(input())):
	s = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	ans = abs(x1 - x2) + abs(y1 - y2)
	if x1 == x2 and x1 == x3 and (min(y1, y2) < y3) and (y3 < max(y1, y2)) or (y1 == y2 and y1 == y3 and (min(x1, x2) < x3) and (x3 < max(x1, x2))):
		ans += 2
	print(ans)


def main():
	t = int(input())
	while t > 0:
		st = input()
		(xa, ya) = map(int, input().split())
		(xb, yb) = map(int, input().split())
		(fx, fy) = map(int, input().split())
		ans = abs(xa - xb) + abs(ya - yb)
		if fx == xa and fx == xb:
			if fy >= min(ya, yb) and fy <= max(ya, yb):
				ans = ans + 2
		if fy == yb and fy == ya:
			if fx >= min(xa, xb) and fx <= max(xa, xb):
				ans = ans + 2
		print(ans)
		t -= 1
main()


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'
mod = 10 ** 9 + 7

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	ans = ''
	for _ in range(ii()):
		I()
		(xa, ya) = mi()
		(xb, yb) = mi()
		(xf, yf) = mi()
		cnt = 0
		if xa == xb:
			cnt = abs(yb - ya)
			if xf == xa and (yf > min(ya, yb) and yf < max(ya, yb)):
				cnt += 2
		elif ya == yb:
			cnt = abs(xa - xb)
			if yf == ya and (xf > min(xa, xb) and xf < max(xa, xb)):
				cnt += 2
		else:
			cnt = abs(yb - ya) + abs(xa - xb)
		ans += str(cnt) + '\n'
	print(ans)
main()


import sys
pin = sys.stdin.readline
T = int(pin())
pin()
for t in range(T):
	A = [*map(int, pin().split())]
	B = [*map(int, pin().split())]
	F = [*map(int, pin().split())]
	pin()
	ans = abs(A[0] - B[0]) + abs(A[1] - B[1])
	if A[0] == B[0] == F[0] and (A[1] <= F[1] <= B[1] or A[1] >= F[1] >= B[1]):
		ans += 2
	if A[1] == B[1] == F[1] and (A[0] <= F[0] <= B[0] or A[0] >= F[0] >= B[0]):
		ans += 2
	print(ans)


t = int(input())
while t != 0:
	a = input()
	(x, y) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(f, f1) = map(int, input().split())
	if x == x1:
		maxi = max(y, y1)
		mini = min(y, y1)
		res = maxi - mini
		if mini < f1 < maxi and f == x:
			res += 2
		print(res)
	elif y == y1:
		maxi = max(x, x1)
		mini = min(x, x1)
		res = maxi - mini
		if mini < f < maxi and f1 == y:
			res += 2
		print(res)
	else:
		n = abs(x - x1)
		m = abs(y - y1)
		res = n + m
		print(res)
	t -= 1


for _ in range(int(input())):
	a = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(f1, f2) = map(int, input().split())
	if x1 != x2 and y1 != y2:
		print(abs(x2 - x1) + abs(y2 - y1))
		continue
	if x1 == x2:
		if f1 != x1:
			print(abs(y2 - y1))
			continue
		else:
			if f2 > min(y1, y2) and f2 < max(y1, y2):
				print(abs(y2 - y1) + 2)
			else:
				print(abs(y2 - y1))
			continue
	if y1 == y2:
		if f2 != y1:
			print(abs(x1 - x2))
			continue
		elif f1 > min(x1, x2) and f1 < max(x2, x1):
			print(abs(x1 - x2) + 2)
		else:
			print(abs(x2 - x1))


from sys import stdin

def main():
	cases = int(stdin.readline().strip())
	for i in range(cases):
		blank = stdin.readline()
		(Ax, Ay) = map(int, stdin.readline().split())
		(Bx, By) = map(int, stdin.readline().split())
		(Fx, Fy) = map(int, stdin.readline().split())
		ans = 0
		if (Ax == Bx and Bx == Fx) and min(Ay, By) < Fy < max(Ay, By):
			ans = abs(Ax - Bx) + abs(Ay - By) + 2
		elif (Ay == By and By == Fy) and min(Ax, Bx) < Fx < max(Ax, Bx):
			ans = abs(Ax - Bx) + abs(Ay - By) + 2
		else:
			ans = abs(Ax - Bx) + abs(Ay - By)
		print(ans)
main()


for _ in range(int(input())):
	input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	if x1 == x2 == x3:
		if y1 < y3 < y2 or y2 < y3 < y1:
			print(abs(y1 - y2) + 2)
		else:
			print(abs(y1 - y2))
	elif y1 == y2 == y3:
		if x1 < x3 < x2 or x2 < x3 < x1:
			print(abs(x1 - x2) + 2)
		else:
			print(abs(x1 - x2))
	else:
		print(abs(x1 - x2) + abs(y1 - y2))


for z in range(int(input())):
	p = input()
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(fx, fy) = map(int, input().split())
	if ax == bx == fx and (ay < fy < by or by < fy < ay) or (ay == by == fy and (ax < fx < bx or bx < fx < ax)):
		if ay == by:
			print(abs(bx - ax) + 2)
		else:
			print(abs(by - ay) + 2)
	else:
		print(abs(by - ay) + abs(bx - ax))


def solve():
	t = int(input())
	paths = []
	for i in range(t):
		input()
		a = list(map(int, input().split(' ')))
		b = list(map(int, input().split(' ')))
		f = list(map(int, input().split(' ')))
		if a[0] == f[0] and a[0] == b[0]:
			if f[1] < max(a[1], b[1]) and f[1] > min(a[1], b[1]):
				paths.append(abs(a[1] - b[1]) + 2)
			else:
				paths.append(abs(a[1] - b[1]))
		elif a[1] == f[1] and a[1] == b[1]:
			if f[0] < max(a[0], b[0]) and f[0] > min(a[0], b[0]):
				paths.append(abs(a[0] - b[0]) + 2)
			else:
				paths.append(abs(a[0] - b[0]))
		else:
			paths.append(abs(a[0] - b[0]) + abs(a[1] - b[1]))
	print('\n')
	for i in paths:
		print(i)
solve()


for _ in range(int(input())):
	res = input()
	(n1, m1) = map(int, input().split())
	(n2, m2) = map(int, input().split())
	(x, y) = map(int, input().split())
	ans = 0
	if n1 == n2 and n1 == x:
		if m1 <= y and y <= m2 or (m2 <= y and y <= m1):
			ans = abs(n1 - n2) + abs(m2 - m1) + 2
		else:
			ans = abs(n1 - n2) + abs(m2 - m1)
	elif m1 == m2 and m1 == y:
		if n1 <= x and x <= n2 or (n2 <= x and x <= n1):
			ans = abs(n1 - n2) + abs(m2 - m1) + 2
		else:
			ans = abs(n1 - n2) + abs(m2 - m1)
	else:
		ans = abs(n1 - n2) + abs(m2 - m1)
	print(ans)


from sys import stdin, stdout
from io import StringIO

def between(x1, x2, x3):
	return x1 < x2 < x3 or x1 > x2 > x3

def linear_between(u, v, w):
	return u[0] == v[0] == w[0] and between(u[1], v[1], w[1]) or (u[1] == v[1] == w[1] and between(u[0], v[0], w[0]))

def main(inbuf, outbuf):
	t = int(inbuf.readline())
	for _ in range(t):
		_ = inbuf.readline()
		a = tuple(map(int, inbuf.readline().split()))
		b = tuple(map(int, inbuf.readline().split()))
		f = tuple(map(int, inbuf.readline().split()))
		correction = 2 if linear_between(a, f, b) else 0
		dist = abs(a[0] - b[0]) + abs(a[1] - b[1]) + correction
		print(str(dist), file=outbuf, end='\n')
outbuf = StringIO()
main(stdin, outbuf)
print(outbuf.getvalue(), file=stdout)


for i in range(int(input())):
	a = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	ans = abs(x1 - x2) + abs(y1 - y2)
	if y1 == y2 and y2 == y3 and (x3 > min(x1, x2)) and (x3 < max(x1, x2)) or (x1 == x2 and x2 == x3 and (y3 > min(y1, y2)) and (y3 < max(y1, y2))):
		ans += 2
	print(ans)


from sys import *
from math import *
from collections import *
import string
import re
from bisect import *
from functools import reduce
from itertools import permutations, combinations
t = stdin.readline
R = range
p = stdout.write
mod = int(1000000000.0) + 7
MAX = 9223372036854775808
INF = float('inf')
lower = string.ascii_lowercase
upper = string.ascii_uppercase
numbers = string.digits
S = lambda : t().strip()
I = lambda : int(t())
GI = lambda : map(int, input().strip().split())
GS = lambda : map(str, t().strip().split())
IL = lambda : list(map(int, t().strip().split()))
SL = lambda : list(map(str, t().strip().split()))
mat = lambda n: [IL() for i in range(n)]
d2b = lambda n: bin(n)[2:]
ispow2 = lambda x: x != 0 and x & x - 1 == 0
powof2 = lambda x: 1 << x
iSq = lambda x: ceil(float(sqrt(x))) == floor(float(sqrt(x)))

def sieve(n):
	return reduce(lambda r, x: r - set(range(x ** 2, n, x)) if x in r else r, range(2, int(n ** 0.5) + 1), set(range(2, n)))

def ls(x, y):
	return x << y

def rs(x, y):
	return x << y

def BS_left(n, a, x):
	i = bisect_left(a, x)
	return [-1, i][i != n and a[i] == x]

def BS_right(n, a, x):
	i = bisect_right(a, x)
	return [-1, i][i != n and a[i] == x]
for _ in range(I()):
	t()
	(xa, ya) = GI()
	(xb, yb) = GI()
	(xf, yf) = GI()
	ans = abs(xa - xb) + abs(ya - yb)
	if xa == xb == xf and (ya < yf < yb or ya > yf > yb) or (ya == yb == yf and (xa < xf < xb or xa > xf > xb)):
		ans += 2
	print(ans)


for _ in range(int(input())):
	s = input()
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(x, y) = map(int, input().split())
	gen = abs(d - b) + abs(c - a)
	if min(a, c) <= x <= max(a, c) and min(b, d) <= y <= max(b, d):
		if a == c == x:
			print(gen + 2)
		elif b == d == y:
			print(gen + 2)
		else:
			print(gen)
	else:
		print(gen)


import sys
import math

def read_int():
	return int(sys.stdin.readline())

def read_ints():
	return list(map(int, sys.stdin.readline().split()))

def write(x):
	sys.stdout.write(x + '\n')
for i in range(int(input())):
	b = input()
	(xa, ya) = read_ints()
	(xb, yb) = read_ints()
	(xf, yf) = read_ints()
	ans = abs(xa - xb) + abs(ya - yb)
	if xa == xf == xb and min(ya, yb) < yf < max(ya, yb) or (ya == yf == yb and min(xa, xb) < xf < max(xa, xb)):
		ans += 2
	write(str(ans))


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xo, yo) = map(int, input().split())
	if xa == xb == xo and (ya >= yo >= yb or ya <= yo <= yb):
		print(abs(xa - xb) + abs(ya - yb) + 2)
		continue
	if ya == yb == yo and (xa >= xo >= xb or xa <= xo <= xb):
		print(abs(xa - xb) + abs(ya - yb) + 2)
		continue
	else:
		print(abs(xa - xb) + abs(ya - yb))
		continue
print('\n'.join(ANS))


t = int(input())
li = []
for i in range(t):
	n = input()
	(xa, xb) = map(int, input().split())
	(ya, yb) = map(int, input().split())
	(fa, fb) = map(int, input().split())
	ans = abs(xa - ya) + abs(xb - yb)
	if xa == ya and xa == fa and (xb > fb and yb < fb or (xb < fb and yb > fb)):
		ans += 2
	elif xb == yb and xb == fb and (xa > fa and ya < fa or (xa < fa and ya > fa)):
		ans += 2
	li.append(ans)
for i in range(len(li)):
	print(li[i])


t = int(input())
for i in range(t):
	n = input()
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(tx, ty) = map(int, input().split())
	if ax != bx and ay != by:
		print(max(ax, bx) - min(ax, bx) + max(ay, by) - min(ay, by))
	elif ax == bx:
		if tx == ax and min(ay, by) < ty < max(ay, by):
			print(max(ay, by) - min(ay, by) + 2)
		else:
			print(max(ay, by) - min(ay, by))
	elif ty == ay and min(ax, bx) < tx < max(ax, bx):
		print(max(ax, bx) - min(ax, bx) + 2)
	else:
		print(max(ax, bx) - min(ax, bx))


t = int(input())
for _ in range(t * 2):
	if _ % 2 == 1:
		(ax, ay) = [int(x) for x in input().split()]
		(bx, by) = [int(x) for x in input().split()]
		(fx, fy) = [int(x) for x in input().split()]
		if ax == bx == fx and min(ay, by) < fy < max(ay, by):
			print(abs(ax - bx) + abs(ay - by) + 2)
		elif ay == by == fy and min(ax, bx) < fx < max(ax, bx):
			print(abs(ax - bx) + abs(ay - by) + 2)
		else:
			print(abs(ax - bx) + abs(ay - by))
	else:
		a = input()


ans = []
for _ in range(int(input())):
	input()
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(fx, fy) = map(int, input().split())
	dist = abs(bx - ax) + abs(by - ay)
	if ay == by and ay == fy and (fx > ax and fx < bx or (fx > bx and fx < ax)):
		dist += 2
	if ax == bx and ax == fx and (fy > ay and fy < by or (fy > by and fy < ay)):
		dist += 2
	ans.append(dist)
for i in ans:
	print(i)


test_cases = int(input())
_ = input()
tests = []
for _ in range(test_cases - 1):
	a_cord = list(map(lambda x: int(x), input().split()))
	b_cord = list(map(lambda x: int(x), input().split()))
	f_cord = list(map(lambda x: int(x), input().split()))
	ignore = input()
	temp = [a_cord, b_cord, f_cord]
	tests.append(temp)
if test_cases != 1:
	a_cord = list(map(lambda x: int(x), input().split()))
	b_cord = list(map(lambda x: int(x), input().split()))
	f_cord = list(map(lambda x: int(x), input().split()))
	temp = [a_cord, b_cord, f_cord]
	tests.append(temp)
for test in tests:
	a_cord = test[0]
	b_cord = test[1]
	f_cord = test[2]
	dist = 0
	dist += abs(b_cord[0] - a_cord[0])
	dist += abs(b_cord[1] - a_cord[1])
	if f_cord[0] == a_cord[0] and f_cord[0] == b_cord[0] or (f_cord[1] == b_cord[1] and f_cord[1] == a_cord[1]):
		if f_cord[0] > a_cord[0] and f_cord[0] > b_cord[0] or (f_cord[1] > a_cord[1] and f_cord[1] > b_cord[1]) or (f_cord[0] < a_cord[0] and f_cord[0] < b_cord[0]) or (f_cord[1] < a_cord[1] and f_cord[1] < b_cord[1]):
			dist -= 2
		dist += 2
	print(dist)


def finddistance(xA, yA, xB, yB, xF, yF):
	if xA > xB:
		(xA, xB) = (xB, xA)
	if yA > yB:
		(yA, yB) = (yB, yA)
	if xA == xB == xF and yA < yF < yB or (yA == yB == yF and xA < xF < xB):
		return abs(xA - xB) + abs(yA - yB) + 2
	return abs(xA - xB) + abs(yA - yB)
t = int(input())
for i in range(t):
	input()
	(xA, yA) = map(int, input().split())
	(xB, yB) = map(int, input().split())
	(xF, yF) = map(int, input().split())
	print(finddistance(xA, yA, xB, yB, xF, yF))


def find_shortest_path_len(xA, yA, xB, yB, xF, yF):
	air_path = abs(xA - xB) + abs(yA - yB)
	c = 0
	if xA == xB == xF:
		if yA < yF < yB or yB < yF < yA:
			c = 2
	if yA == yB == yF:
		if xA < xF < xB or xB < xF < xA:
			c = 2
	return air_path + c
import sys
T = int(input())
while T:
	sys.stdin.readline()
	(xA, yA) = list(map(int, sys.stdin.readline().split()))
	(xB, yB) = list(map(int, sys.stdin.readline().split()))
	(xF, yF) = list(map(int, sys.stdin.readline().split()))
	print(find_shortest_path_len(xA, yA, xB, yB, xF, yF))
	T -= 1


f = filter(str.strip, open(0))
R = lambda : map(int, next(f).split())
(t,) = R()
while t:
	t -= 1
	((k, (u, v, w)), (m, (x, y, z))) = sorted(((len({*x}), x) for x in zip(R(), R(), R())))
	print(abs(u - v) + abs(x - y) + 2 * (k < 2 and (x - z) * (y - z) < 0))


def getlist():
	return list(map(int, input().split()))

def main():
	t = int(input())
	for num in range(t):
		temp = input()
		(x, y) = map(int, input().split())
		(m, n) = map(int, input().split())
		(a, b) = map(int, input().split())
		if x == m:
			if a == m and b in range(min(y, n), max(y, n)):
				length = abs(y - n) + 2
			else:
				length = abs(y - n)
		elif y == n:
			if b == n and a in range(min(x, m), max(x, m)):
				length = abs(x - m) + 2
			else:
				length = abs(x - m)
		else:
			length = abs(x - m) + abs(y - n)
		print(length)
main()


import sys
from collections import deque
input = sys.stdin.readline
t = int(input())
results = []
while t > 0:
	temp = input()
	t -= 1
	(A1, A2) = map(int, input().rstrip().split())
	(B1, B2) = map(int, input().rstrip().split())
	(F1, F2) = map(int, input().rstrip().split())
	a = (A1, A2)
	b = (B1, B2)
	f = (F1, F2)
	if A1 == B1 and B1 == F1:
		if min(A2, B2) <= F2 and F2 <= max(A2, B2):
			results.append(abs(B2 - A2) + 2)
		else:
			results.append(abs(B2 - A2))
	elif A2 == B2 and B2 == F2:
		if min(A1, B1) <= F1 and F1 <= max(A1, B1):
			results.append(abs(B1 - A1) + 2)
		else:
			results.append(abs(B1 - A1))
	else:
		results.append(abs(B1 - A1) + abs(B2 - A2))
for i in results:
	print(i)


t = int(input())
for i in range(t):
	input()
	(ax, ay) = list(map(int, input().split()))
	(bx, by) = list(map(int, input().split()))
	(fx, fy) = list(map(int, input().split()))
	if ax != bx and ay != by:
		print(abs(bx - ax) + abs(by - ay))
	elif fx > ax and fx < bx and (ay == by == fy) or (fx > bx and fx < ax and (ay == by == fy)) or (fy > ay and fy < by and (ax == bx == fx)) or (fy > by and fy < ay and (ax == bx == fx)):
		print(abs(bx - ax) + abs(by - ay) + 2)
	else:
		print(abs(bx - ax) + abs(by - ay))


def main():
	t = int(input())
	for _ in range(t):
		input()
		(xa, ya) = map(int, input().split())
		(xb, yb) = map(int, input().split())
		(xf, yf) = map(int, input().split())
		ans = abs(xa - xb) + abs(ya - yb)
		if xa == xb and xa == xf and (min(ya, yb) < yf < max(ya, yb)) or (ya == yb and ya == yf and (min(xa, xb) < xf < max(xa, xb))):
			ans += 2
		print(ans)
main()


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	a = stdin.readline()
	(xa, ya) = list(map(int, stdin.readline().rstrip().split()))
	(xb, yb) = list(map(int, stdin.readline().rstrip().split()))
	(xf, yf) = list(map(int, stdin.readline().rstrip().split()))
	if xa != xb and ya != yb:
		print(abs(xa - xb) + abs(ya - yb))
	else:
		ans = abs(xa - xb) + abs(ya - yb)
		if xa == xb and ya == yb:
			print(0)
		else:
			if xa == xb and xa == xf and (yf > min(ya, yb)) and (yf < max(ya, yb)) or ((ya == yb and ya == yf) and xf > min(xa, xb) and (xf < max(xa, xb))):
				ans += 2
			print(ans)


t = int(input())
for i in range(t):
	ignore_space = input()
	(xa, ya) = input().split()
	(xb, yb) = input().split()
	(xf, yf) = input().split()
	xa = int(xa)
	ya = int(ya)
	xb = int(xb)
	yb = int(yb)
	xf = int(xf)
	yf = int(yf)
	if xa == xb:
		if xa == xf:
			if yb < yf < ya or yb > yf > ya:
				print(abs(xa - xb) + abs(ya - yb) + 2)
			else:
				print(abs(xa - xb) + abs(ya - yb))
		else:
			print(abs(xa - xb) + abs(ya - yb))
	elif ya == yb:
		if ya == yf:
			if xb < xf < xa or xb > xf > xa:
				print(abs(xa - xb) + abs(ya - yb) + 2)
			else:
				print(abs(xa - xb) + abs(ya - yb))
		else:
			print(abs(xa - xb) + abs(ya - yb))
	else:
		print(abs(xa - xb) + abs(ya - yb))


t = int(input())
for i in range(t):
	e = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	if x1 == x2 and x2 == x3 and (min(y1, y2) < y3 < max(y1, y2)) or (y1 == y2 and y2 == y3 and (min(x1, x2) < x3 < max(x1, x2))):
		print(abs(x1 - x2) + abs(y1 - y2) + 2)
	else:
		print(abs(x1 - x2) + abs(y1 - y2))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	line = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	ans = abs(x1 - x2) + abs(y1 - y2)
	if x1 == x2 and x2 == x3:
		if y1 < y3 < y2 or y2 < y3 < y1:
			ans += 2
	elif y1 == y2 and y2 == y3:
		if x1 < x3 < x2 or x2 < x3 < x1:
			ans += 2
	print(ans)


for i in range(int(input())):
	n = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	rxab = abs(xb - xa)
	ryab = abs(yb - ya)
	rxaf = abs(xf - xa)
	ryaf = abs(yf - ya)
	rxfb = abs(xb - xf)
	ryfb = abs(yb - yf)
	if ya == yb == yf and rxab == rxaf + rxfb or (xa == xb == xf and ryab == ryaf + ryfb):
		r = 2
	else:
		r = 0
	r += rxab + ryab
	print(r)


import sys
input = sys.stdin.readline
output = sys.stdout.write

def main():
	tests = int(input().rstrip())
	for i in range(tests):
		input()
		(xa, ya) = map(int, input().rstrip().split())
		(xb, yb) = map(int, input().rstrip().split())
		(xf, yf) = map(int, input().rstrip().split())
		ans = abs(xa - xb) + abs(ya - yb)
		if xa == xb == xf:
			if ya < yf < yb or yb < yf < ya:
				ans += 2
		elif ya == yb == yf:
			if xa < xf < xb or xb < xf < xa:
				ans += 2
		output(str(ans))
		output('\n')
main()


for f in range(int(input())):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	res = abs(xa - xb) + abs(ya - yb)
	if xf == xa == xb and min(ya, yb) < yf < max(ya, yb):
		res += 2
	elif yf == ya == yb and min(xa, xb) < xf < max(xa, xb):
		res += 2
	print(res)


for _ in range(int(input())):
	input()
	(xA, yA) = map(int, input().split())
	(xB, yB) = map(int, input().split())
	(xF, yF) = map(int, input().split())
	if xA == xB == xF and min(yA, yB) < yF < max(yA, yB) or (yA == yB == yF and min(xA, xB) < xF < max(xA, xB)):
		print(abs(xA - xB) + abs(yA - yB) + 2)
	else:
		print(abs(xA - xB) + abs(yA - yB))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main(t):
	s = input()
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(f1, f2) = map(int, input().split())
	ans = abs(b1 - a1) + abs(b2 - a2)
	if a2 == b2 and b2 == f2 and (a1 < f1 < b1 or b1 < f1 < a1):
		ans += 2
	elif a1 == b1 and b1 == f1 and (a2 < f2 < b2 or b2 < f2 < a2):
		ans += 2
	print(ans)
T = int(input())
t = 1
while t <= T:
	main(t)
	t += 1


t = 0
t = int(input())
shortest_dist = []
for i in range(t):
	input()
	(a_x, a_y) = map(int, input().split())
	(b_x, b_y) = map(int, input().split())
	(t_x, t_y) = map(int, input().split())
	shortest = int(abs(a_x - b_x)) + int(abs(a_y - b_y))
	if a_x == b_x and a_x == t_x or (a_y == b_y and a_y == t_y):
		if a_y == b_y:
			(min_x, max_x) = (a_x, b_x) if a_x <= b_x else (b_x, a_x)
			if min_x < t_x < max_x:
				shortest += 2
		elif a_x == b_x:
			(min_y, max_y) = (a_y, b_y) if a_y <= b_y else (b_y, a_y)
			if min_y < t_y < max_y:
				shortest += 2
	shortest_dist.append(shortest)
for i in range(t):
	print(shortest_dist[i])


class coordinates:

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def get_x(self):
		return self.x

	def get_y(self):
		return self.y
n = int(input())
a = []
b = []
f = []
for i in range(n):
	input()
	(x, y) = input().split(' ')
	a.append(coordinates(int(x), int(y)))
	(x, y) = input().split(' ')
	b.append(coordinates(int(x), int(y)))
	(x, y) = input().split(' ')
	f.append(coordinates(int(x), int(y)))
for i in range(n):
	result = abs(a[i].get_x() - b[i].get_x()) + abs(a[i].get_y() - b[i].get_y())
	if a[i].get_x() == b[i].get_x() and a[i].get_x() == f[i].get_x():
		if f[i].get_y() < a[i].get_y() and f[i].get_y() < b[i].get_y() or (f[i].get_y() > a[i].get_y() and f[i].get_y() > b[i].get_y()):
			pass
		else:
			result += 2
	if a[i].get_y() == b[i].get_y() and a[i].get_y() == f[i].get_y():
		if f[i].get_x() < a[i].get_x() and f[i].get_x() < b[i].get_x() or (f[i].get_x() > a[i].get_x() and f[i].get_x() > b[i].get_x()):
			pass
		else:
			result += 2
	print(result)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(3 * 10 ** 5)

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	s = st()
	(ax, ay) = ma()
	(bx, by) = ma()
	(fx, fy) = ma()
	z = abs(ax - bx) + abs(by - ay)
	if ay == by and fy == ay:
		if fx >= min(ax, bx) and fx <= max(ax, bx):
			z += 2
	if bx == ax and ax == fx:
		if fy >= min(ay, by) and fy <= max(by, ay):
			z += 2
	print(z)


def solve():
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(c1, c2) = map(int, input().split())
	if a1 == b1 and b1 == c1:
		if a2 < c2 and c2 < b2 or (b2 < c2 and c2 < a2):
			print(abs(a2 - b2) + 2)
			return
		else:
			print(abs(a2 - b2))
			return
	if a2 == b2 and b2 == c2:
		if a1 < c1 and c1 < b1 or (b1 < c1 and c1 < a1):
			print(abs(a1 - b1) + 2)
			return
		else:
			print(abs(a1 - b1))
			return
	ans = abs(a1 - b1) + abs(a2 - b2)
	print(ans)
for testis in range(int(input())):
	x = input()
	solve()


t = int(input())
for i in range(t):
	n = input()
	(a, b) = [int(j) for j in input().split()]
	(c, d) = [int(j) for j in input().split()]
	(e, f) = [int(j) for j in input().split()]
	path = abs(a - c) + abs(b - d) + 2 * ((a == c == e) * (b - f) * (d - f) | (b == d == f) * (a - e) * (c - e) < 0)
	print(path)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	emp = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	ans = abs(xa - xb) + abs(ya - yb)
	if xa == xb and xa == xf and (yf > min(ya, yb)) and (yf < max(ya, yb)):
		ans += 2
	if ya == yb and yb == yf and (xf > min(xa, xb)) and (xf < max(xa, xb)):
		ans += 2
	sys.stdout.write(str(ans) + '\n')


import math
t = int(input())
for i in range(t):
	k = input()
	(xa, ya) = list(map(int, input().split()))
	(xb, yb) = list(map(int, input().split()))
	(xf, yf) = list(map(int, input().split()))
	if xa == xb == xf:
		if yf > min(ya, yb) and yf < max(ya, yb):
			print(abs(ya - yb) + 2)
		else:
			print(abs(ya - yb))
	elif ya == yb == yf:
		if xf > min(xa, xb) and xf < max(xa, xb):
			print(abs(xa - xb) + 2)
		else:
			print(abs(xa - xb))
	else:
		print(abs(xa - xb) + abs(ya - yb))


t = int(input())
input()
for i in range(t):
	a = [int(j) for j in input().split(' ')]
	b = [int(j) for j in input().split(' ')]
	c = [int(j) for j in input().split(' ')]
	e = abs(a[0] - b[0]) + abs(a[1] - b[1])
	if a[0] == b[0] and a[0] == c[0] and (a[1] < c[1] < b[1] or b[1] < c[1] < a[1]):
		e += 2
	if a[1] == b[1] and a[1] == c[1] and (a[0] < c[0] < b[0] or b[0] < c[0] < a[0]):
		e += 2
	print(e)
	if i < t - 1:
		input()


for _ in range(int(input())):
	arr = []
	input()
	for i in range(3):
		arr.append(list(map(int, input().split())))
	(x1, y1) = arr[0]
	(x2, y2) = arr[1]
	(x3, y3) = arr[2]
	ans = abs(x2 - x1) + abs(y1 - y2)
	if x1 == x2 == x3 and (y1 < y3 < y2 or y2 < y3 < y1) or (y1 == y2 == y3 and (x1 < x3 < x2 or x2 < x3 < x1)):
		ans += 2
	print(ans)


def s(x1, y1, x2, y2, x3, y3):
	if x1 == x2 == x3:
		if y1 < y3 < y2 or y2 < y3 < y1:
			return abs(y1 - y2) + 2
		else:
			return abs(y1 - y2)
	elif y1 == y2 == y3:
		if x1 < x3 < x2 or x2 < x3 < x1:
			return abs(x1 - x2) + 2
		else:
			return abs(x1 - x2)
	else:
		return abs(x1 - x2) + abs(y1 - y2)
a = int(input())
for _ in range(a):
	input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	print(s(x1, y1, x2, y2, x3, y3))


tc = int(input())
input()
while tc:
	tc -= 1
	(a, b, f) = (list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split())))
	if tc:
		input()
	extra = 0
	if a[0] == b[0] == f[0] and min(a[1], b[1]) < f[1] < max(a[1], b[1]) or (a[1] == b[1] == f[1] and min(a[0], b[0]) < f[0] < max(a[0], b[0])):
		extra = 2
	print(extra + abs(b[1] - a[1]) + abs(b[0] - a[0]))


import math

def ex_9_calculating(data):
	(a, b, f) = data
	if a[0] != b[0] and a[1] != b[1]:
		steps = math.fabs(a[0] - b[0]) + math.fabs(a[1] - b[1])
	if a[0] == b[0]:
		if f[0] != a[0]:
			steps = math.fabs(a[1] - b[1])
		elif f[0] == a[0] and f[1] in range(min(a[1], b[1]), max(a[1], b[1])):
			steps = math.fabs(a[1] - b[1]) + 2
		else:
			steps = math.fabs(a[1] - b[1])
	elif a[1] == b[1]:
		if f[1] != a[1]:
			steps = math.fabs(a[0] - b[0])
		elif f[1] == a[1] and f[0] in range(min(a[0], b[0]), max(a[0], b[0])):
			steps = math.fabs(a[0] - b[0]) + 2
		else:
			steps = math.fabs(a[0] - b[0])
	return int(steps)
tests = int(input())
data = {}
for i in range(tests):
	data[i] = []
	for j in range(4):
		data[i].append([int(x) for x in input().split()])
	data[i].pop(0)
for key in data.keys():
	print(ex_9_calculating(data[key]))


t = int(input())
while t > 0:
	coor = []
	input()
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(fx, fy) = map(int, input().split())
	(h, k) = sorted([ax, bx])
	(i, j) = sorted([ay, by])
	d = abs(ax - bx) + abs(ay - by)
	if ax == bx or ay == by:
		if fx == ax or fy == ay:
			if (fx < ax and fx > bx or (fx > ax and fx < bx)) or (fy > ay and fy < by or (fy < ay and fy > by)):
				print(d + 2)
			else:
				print(d)
		else:
			print(d)
	else:
		print(d)
	t -= 1


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	stdin.readline()
	(xa, ya) = map(int, stdin.readline().split())
	(xb, yb) = map(int, stdin.readline().split())
	(xf, yf) = map(int, stdin.readline().split())
	d = abs(xa - xb) + abs(ya - yb)
	if xf == xa and xf == xb and (min(ya, yb) < yf < max(ya, yb)) or (yf == ya and yf == yb and (min(xa, xb) < xf < max(xa, xb))):
		d += 2
	print(d)


t = int(input())
for i in range(t):
	s = input()
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	f = [int(x) for x in input().split()]
	(xa, ya) = (a[0], a[1])
	(xb, yb) = (b[0], b[1])
	(xf, yf) = (f[0], f[1])
	if xa != xb and ya != yb:
		print(abs(yb - ya) + abs(xb - xa))
	elif (xf > xa and xf < xb or (xf < xa and xf > xb)) and (yf == ya or yf == yb) or ((yf > ya and yf < yb or (yf < ya and yf > yb)) and (xf == xa or xf == xb)):
		if yb == ya:
			print(2 + abs(xb - xa))
		else:
			print(2 + abs(yb - ya))
	elif yb == ya:
		print(abs(xb - xa))
	else:
		print(abs(yb - ya))


import sys
import bisect

def get_line():
	return list(map(int, sys.stdin.readline().strip().split()))

def in1():
	return int(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')
for _ in range(in1()):
	t = get_line()
	(a1, a2) = get_line()
	(b1, b2) = get_line()
	(f1, f2) = get_line()
	if a1 == b1 and f1 == a1 and (f2 >= a2 and f2 <= b2 or (f2 >= b2 and f2 <= a2)):
		print(abs(a1 - b1) + abs(a2 - b2) + 2)
	elif a2 == b2 and f2 == a2 and (f1 >= a1 and f1 <= b1 or (f1 >= b1 and f1 <= a1)):
		print(abs(a1 - b1) + abs(a2 - b2) + 2)
	else:
		print(abs(a1 - b1) + abs(a2 - b2))


import math
for i in range(int(input())):
	emp = input()
	(xa, ya) = [int(x) for x in input().split()]
	(xb, yb) = [int(x) for x in input().split()]
	(xf, yf) = [int(x) for x in input().split()]
	if xa == xb == xf and ya == yb == yf:
		print(0)
		continue
	if xa == xb == xf:
		if min(ya, yb) <= yf <= max(ya, yb):
			print(abs(ya - yb) + 2)
		else:
			print(abs(ya - yb))
		continue
	if ya == yb == yf:
		if min(xa, xb) <= xf <= max(xa, xb):
			print(abs(xa - xb) + 2)
		else:
			print(abs(xa - xb))
		continue
	print(abs(xa - xb) + abs(ya - yb))


import math
t = int(input())
while t:
	input()
	(a1, a2) = [int(x) for x in input().split()]
	(b1, b2) = [int(x) for x in input().split()]
	(f1, f2) = [int(x) for x in input().split()]
	if f1 - a1 != 0:
		a = (f2 - a2) / (f1 - a1)
	else:
		a = None
	if b1 - f1 != 0:
		b = (b2 - f2) / (b1 - f1)
	else:
		b = None
	f = math.sqrt((a2 - f2) ** 2 + (a1 - f1) ** 2)
	l = math.sqrt((a2 - b2) ** 2 + (a1 - b1) ** 2)
	m = math.sqrt((f2 - b2) ** 2 + (f1 - b1) ** 2)
	if a == b and l == f + m:
		if a1 == b1:
			print(abs(b2 - a2) + 2)
		elif a2 == b2:
			print(abs(a1 - b1) + 2)
		else:
			print(abs(a1 - b1) + abs(a2 - b2))
	else:
		print(abs(a1 - b1) + abs(a2 - b2))
	t -= 1


answers = []

def solve(xA, yA, xB, yB, xF, yF):
	if xA == xB:
		least = min(yA, yB)
		highest = max(yA, yB)
		if (yF > least and yF < highest) and xA == xF:
			answers.append(abs(yA - yB) + 2)
		else:
			answers.append(abs(yA - yB))
	elif yA == yB:
		least = min(xA, xB)
		highest = max(xA, xB)
		if (xF > least and xF < highest) and yA == yF:
			answers.append(abs(xA - xB) + 2)
		else:
			answers.append(abs(xA - xB))
	else:
		answers.append(abs(xA - xB) + abs(yA - yB))
T = int(input())
while T:
	temp = input()
	(xA, yA) = [int(x) for x in input().split()]
	(xB, yB) = [int(x) for x in input().split()]
	(xF, yF) = [int(x) for x in input().split()]
	solve(xA, yA, xB, yB, xF, yF)
	T -= 1
for ans in answers:
	print(ans)


from sys import stdin, stdout
input = stdin.readline

def main():
	t = int(input())
	for z in range(t):
		input()
		(x, y) = map(int, input().split())
		(x1, y1) = map(int, input().split())
		(x2, y2) = map(int, input().split())
		ans = abs(x - x1) + abs(y - y1)
		if x == x1 and x2 == x or (y == y1 and y2 == y):
			x3 = min(x1, x)
			x4 = max(x1, x)
			y3 = min(y1, y)
			y4 = max(y1, y)
			if x3 <= x2 and x4 >= x2 and (y3 <= y2) and (y4 >= y2):
				ans += 2
		print(ans)
main()


for testcase in range(int(input())):
	input()
	(XA, YA) = map(int, input().split())
	(XB, YB) = map(int, input().split())
	(XF, YF) = map(int, input().split())
	horizontalDistance = abs(XA - XB)
	verticalDistance = abs(YA - YB)
	shortestPathLength = horizontalDistance + verticalDistance
	if XA == XB == XF and (YA < YF < YB or YB < YF < YA) or (YA == YB == YF and (XA < XF < XB or XB < XF < XA)):
		shortestPathLength += 2
	print(shortestPathLength)


t = int(input())
results = []
for i in range(t):
	input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	if x1 != x2 and y1 != y2:
		results.append(abs(x1 - x2) + abs(y1 - y2))
		continue
	if x1 == x2 != x3 and y1 != y2:
		results.append(abs(x1 - x2) + abs(y1 - y2))
		continue
	if y1 == y2 != y3 and x1 != x2:
		results.append(abs(x1 - x2) + abs(y1 - y2))
		continue
	if x1 == x2 == x3:
		if y1 > y3 > y2 or y2 > y3 > y1:
			results.append(abs(y1 - y2) + 2)
		else:
			results.append(abs(y1 - y2))
		continue
	if y1 == y2 == y3:
		if x1 > x3 > x2 or x2 > x3 > x1:
			results.append(abs(x1 - x2) + 2)
		else:
			results.append(abs(x1 - x2))
		continue
for i in range(t):
	print(results[i])


from sys import stdin

def main():
	cases = int(stdin.readline().strip())
	for _ in range(cases):
		stdin.readline()
		(xa, ya) = map(int, stdin.readline().split())
		(xb, yb) = map(int, stdin.readline().split())
		(xf, yf) = map(int, stdin.readline().split())
		ans = abs(xa - xb) + abs(ya - yb)
		if xa == xb == xf and min(ya, yb) < yf < max(ya, yb) or (ya == yb == yf and min(xa, xb) < xf < max(xa, xb)):
			ans += 2
		print(ans)
main()


import fileinput

def process(line):
	print(line)

def main():
	it = fileinput.input()
	num_cases = int(next(it))
	for i in range(num_cases):
		next(it)
		(x_a, y_a) = list(map(int, next(it).split()))
		(x_b, y_b) = list(map(int, next(it).split()))
		(x_f, y_f) = list(map(int, next(it).split()))
		if x_a == x_b == x_f and (y_a < y_f < y_b or y_b < y_f < y_a):
			print(abs(y_b - y_a) + 2)
		elif y_a == y_b == y_f and (x_a < x_f < x_b or x_b < x_f < x_a):
			print(abs(x_b - x_a) + 2)
		else:
			print(abs(x_b - x_a) + abs(y_b - y_a))
main()


from sys import stdin, stderr
input = stdin.readline

def dbp(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def get_int_list():
	return [int(x) for x in input().strip().split()]

def do_thing():
	input()
	start = get_int_list()
	end = get_int_list()
	block = get_int_list()
	if start[0] == end[0] == block[0]:
		(lo, hi) = sorted([start[1], end[1]])
		if lo < block[1] < hi:
			return hi - lo - 1 + 3
	elif start[1] == end[1] == block[1]:
		(lo, hi) = sorted([start[0], end[0]])
		if lo < block[0] < hi:
			return hi - lo - 1 + 3
	return abs(end[0] - start[0]) + abs(end[1] - start[1])

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
multicase()


def main():
	t = int(input())
	for i in range(t):
		input()
		(xa, ya) = map(int, input().split())
		(xb, yb) = map(int, input().split())
		(xc, yc) = map(int, input().split())
		if xa != xb and ya != yb:
			print(abs(xa - xb) + abs(ya - yb))
		else:
			(xl, xr) = (xa, xb) if xa < xb else (xb, xa)
			(yl, yr) = (ya, yb) if ya < yb else (yb, ya)
			if xa == xb == xc and yl < yc < yr:
				print(2 + yr - yl)
				continue
			if ya == yb == yc and xl < xc < xr:
				print(2 + xr - xl)
				continue
			print(xr - xl + yr - yl)
while True:
	try:
		main()
	except:
		break


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	if xa ^ xb and ya ^ yb:
		ans = abs(xa - xb) + abs(ya - yb)
	else:
		ans = abs(xa - xb) + abs(ya - yb)
		if xa == xb == xf:
			if ya < yf < yb or yb < yf < ya:
				ans += 2
		if ya == yb == yf:
			if xa < xf < xb or xb < xf < xa:
				ans += 2
	print(ans)


n = int(input())
res = []
for i in range(n):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = list(map(int, input().split()))
	if a[0] != b[0] and a[1] != b[1]:
		res.append(abs(a[0] - b[0]) + abs(a[1] - b[1]))
	elif a[0] == b[0]:
		if a[0] == f[0] and (a[1] < f[1] < b[1] or a[1] > f[1] > b[1]):
			res.append(abs(a[1] - b[1]) + 2)
		else:
			res.append(abs(a[1] - b[1]))
	elif a[1] == b[1]:
		if a[1] == f[1] and (a[0] < f[0] < b[0] or a[0] > f[0] > b[0]):
			res.append(abs(a[0] - b[0]) + 2)
		else:
			res.append(abs(a[0] - b[0]))
for i in res:
	print(i)


t = int(input())
while t:
	x = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	if a[0] == b[0] == c[0]:
		if a[1] < c[1] < b[1] or b[1] < c[1] < a[1]:
			ans = abs(a[1] - b[1]) + 2
			print(ans)
		else:
			print(abs(a[1] - b[1]))
	elif a[1] == b[1] == c[1]:
		if a[0] < c[0] < b[0] or b[0] < c[0] < a[0]:
			ans = abs(a[0] - b[0]) + 2
			print(ans)
		else:
			print(abs(a[0] - b[0]))
	else:
		print(abs(a[0] - b[0]) + abs(a[1] - b[1]))
	t -= 1


try:
	t = int(input())
	for _ in range(t):
		input()
		(xa, ya) = [int(x) for x in input().split()]
		(xb, yb) = [int(x) for x in input().split()]
		(xf, yf) = [int(x) for x in input().split()]
		if xa == xb and xb == xf and (min(ya, yb) < yf and max(ya, yb) > yf):
			print(abs(ya - yb) + 2)
		elif ya == yb and yb == yf and (min(xa, xb) < xf and max(xa, xb) > xf):
			print(abs(xa - xb) + 2)
		else:
			print(abs(xa - xb) + abs(ya - yb))
except Exception as e:
	print(e)


for _ in range(int(input())):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	if xa == xb == xf:
		a = min(ya, yb)
		b = max(ya, yb)
		if a <= yf <= b:
			print(abs(ya - yb) + 2)
		else:
			print(abs(ya - yb))
	elif ya == yb == yf:
		c = min(xa, xb)
		d = max(xa, xb)
		if c <= xf <= d:
			print(abs(xa - xb) + 2)
		else:
			print(abs(xa - xb))
	else:
		print(abs(xa - xb) + abs(ya - yb))


t = int(input())
while t:
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	if xa == xb == xf and min(ya, yb) < yf and (max(ya, yb) > yf):
		print(abs(ya - yb) + 2)
	elif ya == yb == yf and min(xa, xb) < xf and (max(xa, xb) > xf):
		print(abs(xa - xb) + 2)
	else:
		print(abs(xa - xb) + abs(ya - yb))
	t -= 1


def abs(x):
	if x > 0:
		return x
	else:
		return -x

def minLength(start, stop, obs):
	if start[0] != stop[0] and start[1] != stop[1]:
		return abs(start[0] - stop[0]) + abs(start[1] - stop[1])
	elif start[0] == stop[0] and start[0] == obs[0] and (abs(start[1]) < abs(obs[1]) < abs(stop[1]) or abs(stop[1]) < abs(obs[1]) < abs(start[1])):
		return abs(start[1] - stop[1]) + 2
	elif start[1] == stop[1] and start[1] == obs[1] and (abs(start[0]) < abs(obs[0]) < abs(stop[0]) or abs(stop[0]) < abs(obs[0]) < abs(start[0])):
		return abs(start[0] - stop[0]) + 2
	else:
		return abs(start[0] - stop[0]) + abs(start[1] - stop[1])

def shortestPath():
	ncases = int(input())
	for case in range(ncases):
		gap = input()
		start = tuple(map(int, input().split()))
		stop = tuple(map(int, input().split()))
		obs = tuple(map(int, input().split()))
		print(minLength(start, stop, obs))
shortestPath()


for _ in range(int(input())):
	input()
	colList = []
	rowList = []
	xsum = 0
	ysum = 0
	fsum = 0
	x = list(map(int, input().split()))[:2]
	y = list(map(int, input().split()))[:2]
	f = list(map(int, input().split()))[:2]
	colList.append(x[0])
	colList.append(y[0])
	colList.append(f[0])
	rowList.append(x[1])
	rowList.append(y[1])
	rowList.append(f[1])
	if colList[0] == colList[1] == colList[2]:
		if rowList[0] < rowList[2] < rowList[1] or rowList[1] < rowList[2] < rowList[0]:
			val = abs(rowList[0] - rowList[1]) + 2
			print(val)
		else:
			print(abs(rowList[0] - rowList[1]))
	elif rowList[0] == rowList[1] == rowList[2]:
		if colList[0] < colList[2] < colList[1] or colList[1] < colList[2] < colList[0]:
			val = abs(colList[0] - colList[1]) + 2
			print(val)
		else:
			print(abs(colList[0] - colList[1]))
	else:
		v = abs(colList[0] - colList[1]) + abs(rowList[0] - rowList[1])
		print(v)


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	stdin.readline()
	(xa, ya) = map(int, stdin.readline().split())
	(xb, yb) = map(int, stdin.readline().split())
	(xf, yf) = map(int, stdin.readline().split())
	print(abs(xa - xb) + abs(ya - yb) + 2 * ((xa == xb == xf) * (yf - ya) * (yf - yb) | (ya == yb == yf) * (xf - xa) * (xf - xb) < 0))


def solve():
	q = input()
	(xa, ya) = [int(i) for i in input().split()]
	(xb, yb) = [int(i) for i in input().split()]
	(xf, yf) = [int(i) for i in input().split()]
	if xa == xf and xf == xb and (yf > ya and yf < yb or (yf < ya and yf > yb)) or (ya == yf and yf == yb and (xf > xa and xf < xb or (xf < xa and xf > xb))):
		return abs(ya - yb) + 2 + abs(xa - xb)
	return abs(xa - xb) + abs(ya - yb)
t = int(input())
ans = []
while t:
	ans.append(str(solve()))
	t -= 1
print('\n'.join(ans))


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	temp = input()
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	ans = abs(a - c) + abs(b - d)
	if a == c == e and (b < f < d or d < f < b):
		ans += 2
	if b == d == f and (a < e < c or c < e < a):
		ans += 2
	print(ans)


for _ in range(int(input())):
	empt = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = list(map(int, input().split()))
	count = 0
	check = False
	if a[0] <= b[0] and a[1] <= b[1]:
		pass
	else:
		(a, b) = (b, a)
	if a[0] == b[0] == f[0] and a[1] < f[1] < b[1]:
		check = True
	elif a[1] == b[1] == f[1] and a[0] < f[0] < b[0]:
		check = True
	count += abs(a[0] - b[0])
	count += abs(a[1] - b[1])
	if check:
		count += 2
		print(count)
	else:
		print(count)


import sys
t = int(sys.stdin.readline())
while t > 0:
	sp = sys.stdin.readline()
	(xa, ya) = map(int, sys.stdin.readline().split())
	(xb, yb) = map(int, sys.stdin.readline().split())
	(xf, yf) = map(int, sys.stdin.readline().split())
	ans = abs(xa - xb) + abs(ya - yb)
	if xa == xb and xa == xf:
		if yf < ya and yf > yb or (yf < yb and yf > ya):
			ans += 2
	if ya == yb and ya == yf:
		if xf < xa and xf > xb or (xf < xb and xf > xa):
			ans += 2
	print(ans)
	t -= 1


for input_number in range(int(input())):
	input()
	(xA, yA) = map(int, input().split())
	(xB, yB) = map(int, input().split())
	(xF, yF) = map(int, input().split())
	if xB != xA and yB != yA:
		print(abs(xA - xB) + abs(yA - yB))
	if xB == xA:
		if xA == xF and yF > min(yA, yB) and (yF < max(yA, yB)):
			print(abs(yA - yB) + 2)
		else:
			print(abs(yA - yB))
	elif yA == yB:
		if yA == yF and xF > min(xA, xB) and (xF < max(xA, xB)):
			print(abs(xA - xB) + 2)
		else:
			print(abs(xA - xB))


for _ in range(int(input())):
	input()
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(fx, fy) = map(int, input().split())
	if ax != bx and ay != by:
		print(abs(ax - bx) + abs(ay - by))
	elif ay == by == fy and (ax < fx < bx or bx < fx < ax):
		print(abs(ax - bx) + abs(ay - by) + 2)
	elif ax == bx == fx and (ay < fy < by or by < fy < ay):
		print(abs(ax - bx) + abs(ay - by) + 2)
	else:
		print(abs(ax - bx) + abs(ay - by))


def is_between(xA: int, yA: int, xB: int, yB: int, xF: int, yF: int) -> bool:
	if xA == xB and xB == xF:
		length_AB = abs(yA - yB)
		length_AF = abs(yF - yA)
		length_BF = abs(yB - yF)
		if length_AB == length_AF + length_BF:
			return True
	if yA == yB and yB == yF:
		length_AB = abs(xA - xB)
		length_AF = abs(xF - xA)
		length_BF = abs(xB - xF)
		if length_AB == length_AF + length_BF:
			return True
	return False

def shortest_path_length(xA: int, yA: int, xB: int, yB: int, xF: int, yF: int) -> int:
	path_length = abs(xB - xA) + abs(yB - yA)
	if is_between(xA, yA, xB, yB, xF, yF):
		path_length += 2
	return path_length
n = int(input())
for _ in range(n):
	input()
	(xA, yA) = list(map(int, input().split()))
	(xB, yB) = list(map(int, input().split()))
	(xF, yF) = list(map(int, input().split()))
	print(shortest_path_length(xA, yA, xB, yB, xF, yF))


t = int(input())
natija = []
for i in range(t):
	input()
	(x1, y1) = input().split(' ')
	(x1, y1) = (int(x1), int(y1))
	(x2, y2) = input().split(' ')
	(x2, y2) = (int(x2), int(y2))
	(x3, y3) = input().split(' ')
	(x3, y3) = (int(x3), int(y3))
	if x1 == x2 and x1 == x3 and (y1 <= y3 and y3 <= y2 or (y2 <= y3 and y3 <= y1)) or ((y1 == y2 and y1 == y3) and (x1 <= x3 and x3 <= x2 or (x2 <= x3 and x3 <= x1))):
		natija.append(abs(x1 - x2) + abs(y1 - y2) + 2)
	else:
		natija.append(abs(x1 - x2) + abs(y1 - y2))
for i in range(t):
	print(natija[i])


def is_f_between(a, b, f):
	(xa, ya) = a
	(xb, yb) = b
	(xf, yf) = f
	return xa == xb == xf and (ya > yf and yf > yb or (ya < yf and yf < yb)) or (ya == yb == yf and (xa > xf and xf > xb or (xa < xf and xf < xb)))
t = int(input())
A = [[0, 0]] * t
B = [[0, 0]] * t
F = [[0, 0]] * t
S = [0] * t
for i in range(t):
	input()
	A[i] = list(map(int, input().split()))
	B[i] = list(map(int, input().split()))
	F[i] = list(map(int, input().split()))
	(xa, ya) = A[i]
	(xb, yb) = B[i]
	(xf, yf) = F[i]
	S[i] = abs(xa - xb) + abs(ya - yb)
	if is_f_between(A[i], B[i], F[i]):
		S[i] += 2
for i in range(t):
	print(S[i])


t = int(input())
answers = []
for i in range(t):
	a = input()
	(xa, ya) = map(int, input().split(' '))
	(xb, yb) = map(int, input().split(' '))
	(xf, yf) = map(int, input().split(' '))
	if xa != xb and ya != yb:
		answers.append(abs(xa - xb) + abs(ya - yb))
	elif yf == ya == yb:
		if xa - xb < 0 and xa < xf < xb or (xa - xb > 0 and xa > xf > xb):
			answers.append(abs(xa - xb) + 2)
		else:
			answers.append(abs(xa - xb))
	elif xf == xa == xb:
		if ya - yb < 0 and ya < yf < yb or (ya - yb > 0 and ya > yf > yb):
			answers.append(abs(ya - yb) + 2)
		else:
			answers.append(abs(ya - yb))
	else:
		answers.append(abs(xa - xb) + abs(ya - yb))
for i in range(t):
	print(answers[i])


def func(a, b, f):
	if a[0] == b[0] and a[0] == f[0] and (min(a[1], b[1]) <= f[1] <= max(a[1], b[1])):
		return abs(a[0] - b[0]) + abs(a[1] - b[1]) + 2
	elif a[1] == b[1] and a[1] == f[1] and (min(a[0], b[0]) <= f[0] <= max(a[0], b[0])):
		return abs(a[0] - b[0]) + abs(a[1] - b[1]) + 2
	return abs(a[0] - b[0]) + abs(a[1] - b[1])
t = int(input())
for _ in range(t):
	space = input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = list(map(int, input().split()))
	print(func(a, b, f))


test_num = int(input())
for test in range(test_num):
	input()
	(xa, ya) = input().split()
	xa = int(xa)
	ya = int(ya)
	(xb, yb) = input().split()
	xb = int(xb)
	yb = int(yb)
	(xf, yf) = input().split()
	xf = int(xf)
	yf = int(yf)
	if xa == xb:
		if xf == xa and (ya < yf and yf < yb or (ya > yf and yf > yb)):
			print(abs(yb - ya) + 2)
		else:
			print(abs(yb - ya))
	elif ya == yb:
		if yf == ya and (xa < xf and xf < xb or (xa > xf and xf > xb)):
			print(abs(xb - xa) + 2)
		else:
			print(abs(xb - xa))
	else:
		print(abs(xb - xa) + abs(yb - ya))


t = int(input())
for _ in range(t):
	input()
	arr = list(map(int, input().split()))
	xa = arr[0]
	ya = arr[1]
	arr = list(map(int, input().split()))
	xb = arr[0]
	yb = arr[1]
	arr = list(map(int, input().split()))
	xf = arr[0]
	yf = arr[1]
	if xa == xb:
		if xa == xf and yf > min(ya, yb) and (yf < max(ya, yb)):
			print(abs(ya - yb) + 2)
		else:
			print(abs(ya - yb))
	elif ya == yb:
		if yf == ya and xf > min(xa, xb) and (xf < max(xa, xb)):
			print(abs(xa - xb) + 2)
		else:
			print(abs(xa - xb))
	else:
		print(abs(xa - xb) + abs(ya - yb))


tests = int(input())
for _ in range(tests):
	input()
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	f = list(map(int, input().split()))
	(x, y) = (abs(a[0] - b[0]), abs(a[1] - b[1]))
	if x == 0 and min(a[1], b[1]) < f[1] < max(a[1], b[1]) and (f[0] == a[0]):
		print(x + y + 2)
	elif y == 0 and min(a[0], b[0]) < f[0] < max(a[0], b[0]) and (f[1] == a[1]):
		print(x + y + 2)
	else:
		print(x + y)


n = int(input())
s = str(input())
while n > 0:
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	if n != 1:
		q = str(input())
	ans = abs(a[0] - b[0]) + abs(a[1] - b[1])
	if a[0] == b[0] and a[0] == c[0] and (min(a[1], b[1]) < c[1]) and (c[1] < max(a[1], b[1])) or (a[1] == b[1] and a[1] == c[1] and (min(a[0], b[0]) < c[0]) and (c[0] < max(a[0], b[0]))):
		ans += 2
	n -= 1
	print(ans)


import sys
import math
import heapq
from collections import defaultdict as dd
from collections import OrderedDict as od
from collections import deque
from itertools import permutations as pp
from itertools import combinations as cc
from sys import stdin
from functools import cmp_to_key
from functools import lru_cache
from bisect import bisect_left as bs_l
from bisect import bisect_right as bs_r
input = sys.stdin.readline
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 5)
T = int(input())
for _ in range(T):
	s = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	(xx, yy) = (abs(xa - xb), abs(ya - yb))
	if xx == 0 and xf == xa and (ya < yf < yb or yb < yf < ya):
		xx += 2
	if yy == 0 and yf == ya and (xa < xf < xb or xb < xf < xa):
		yy += 2
	print(xx + yy)


t = int(input())
for i in range(t):
	input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	s = abs(xb - xa) + abs(yb - ya)
	if xa == xb and xb == xf:
		if yb < yf and yf < ya or (yb > yf and yf > ya):
			print(s + 2)
		else:
			print(s)
	elif yb == ya and yb == yf:
		if xa < xf and xf < xb or (xa > xf and xf > xb):
			print(s + 2)
		else:
			print(s)
	else:
		print(s)


t = int(input())
for _ in range(t):
	input()
	(Xa, Ya) = map(int, input().split())
	(Xb, Yb) = map(int, input().split())
	(Xf, Yf) = map(int, input().split())
	ans = abs(Xa - Xb) + abs(Ya - Yb)
	if Xa == Xb == Xf and (Ya < Yf < Yb or Yb < Yf < Ya) or (Ya == Yb == Yf and (Xa < Xf < Xb or Xb < Xf < Xa)):
		ans += 2
	print(ans)


a = int(input())
sol = []
for i in range(a):
	input()
	(ax, ay) = input().split()
	(bx, by) = input().split()
	(fx, fy) = input().split()
	y_dist = abs(int(ay) - int(by))
	x_dist = abs(int(ax) - int(bx))
	sum_dist = x_dist + y_dist
	if y_dist == 0 and int(fy) == int(ay) and (int(fx) > min(int(ax), int(bx))) and (int(fx) < max(int(ax), int(bx))):
		sum_dist = sum_dist + 2
	elif x_dist == 0 and int(fx) == int(ax) and (int(fy) > min(int(ay), int(by))) and (int(fy) < max(int(ay), int(by))):
		sum_dist = sum_dist + 2
	sol.append(sum_dist)
for item in sol:
	print(item)


t = int(input())
for i in range(t):
	blank = input()
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	f = [int(x) for x in input().split()]
	total = b[0] - a[0]
	if total < 0:
		total *= -1
	total2 = b[1] - a[1]
	if total2 < 0:
		total2 *= -1
	if total == 0 and f[0] == a[0] or (total2 == 0 and f[1] == a[1]):
		if f[0] == a[0]:
			if f[1] < a[1] and f[1] > b[1] or (f[1] > a[1] and f[1] < b[1]):
				total += 2
		elif f[0] < a[0] and f[0] > b[0] or (f[0] > a[0] and f[0] < b[0]):
			total += 2
	print(total + total2)


ans = []
for i in range(int(input())):
	s = 0
	buff = input()
	(q, w, e) = (input().split(), input().split(), input().split())
	if q[0] == w[0] == e[0]:
		if int(q[1]) < int(e[1]) < int(w[1]) or int(w[1]) < int(e[1]) < int(q[1]):
			s = 2
	elif q[1] == w[1] == e[1]:
		if int(q[0]) < int(e[0]) < int(w[0]) or int(w[0]) < int(e[0]) < int(q[0]):
			s = 2
	s = s + abs(int(q[0]) - int(w[0])) + abs(int(q[1]) - int(w[1]))
	ans.append(s)
for i in ans:
	print(i, '\n')


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	input()
	(a, A) = rns()
	(b, B) = rns()
	(f, F) = rns()
	ans = abs(a - b) + abs(A - B)
	if a == b and A == B:
		pass
	elif a == b == f:
		(l, r) = sorted([A, B])
		if l <= F <= r:
			ans += 2
	elif A == B == F:
		(l, r) = sorted([a, b])
		if l <= f <= r:
			ans += 2
	else:
		pass
	print(ans)


import sys
import math
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def main():
	for _ in range(get_int()):
		tmp = input()
		(Ay, Ax) = get_ints_in_variables()
		(By, Bx) = get_ints_in_variables()
		(Fy, Fx) = get_ints_in_variables()
		count = 0
		if Ax == Bx and Bx == Fx and (Ay <= Fy <= By or By <= Fy <= Ay):
			count += abs(Ay - By) + abs(Ax - Bx)
			count += 2
		elif Ay == By and By == Fy and (Ax <= Fx <= Bx or Bx <= Fx <= Ax):
			count += abs(Ay - By) + abs(Ax - Bx)
			count += 2
		else:
			count += abs(Ay - By) + abs(Ax - Bx)
		print(count)
main()


x = int(input())
for i in range(x):
	p = input()
	(al, ah) = map(int, input().split())
	(bl, bh) = map(int, input().split())
	(fl, fh) = map(int, input().split())
	if al == bl and al == fl and (abs(ah - bh) == abs(fh - ah) + abs(fh - bh)):
		print(abs(ah - bh) + 2)
	elif ah == bh == fh and abs(al - bl) == abs(fl - al) + abs(fl - bl):
		print(abs(al - bl) + 2)
	else:
		print(abs(al - bl) + abs(ah - bh))


t = int(input())
for _ in range(t):
	tmp = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	res = abs(xa - xb) + abs(ya - yb)
	if xa == xb == xf and min(ya, yb) <= yf <= max(ya, yb) or (ya == yb == yf and min(xa, xb) <= xf <= max(xa, xb)):
		res += 2
	print(res)


T = int(input())
out = []
for t in range(T):
	_ = input()
	(ca, ra) = [int(x) for x in input().split()]
	(cb, rb) = [int(x) for x in input().split()]
	(cf, rf) = [int(x) for x in input().split()]
	req = abs(cb - ca) + abs(rb - ra)
	if ca == cb == cf and (ra <= rf <= rb or rb <= rf <= ra):
		req += 2
	elif ra == rb == rf and (ca <= cf <= cb or cb <= cf <= ca):
		req += 2
	out.append(req)
for e in out:
	print(e)


t = int(input())
for i in range(t):
	trash = input()
	(Ax, Ay) = map(int, input().split())
	(Bx, By) = map(int, input().split())
	(Fx, Fy) = map(int, input().split())
	if Ax != Bx and Ay != By:
		print(abs(Ax - Bx) + abs(Ay - By))
	elif Ax == Bx and Ay != By:
		if Fx == Ax and min(Ay, By) < Fy < max(Ay, By):
			print(abs(Ay - By) + 2)
		else:
			print(abs(Ay - By))
	elif Ay == By and Ax != Bx:
		if Fy == Ay and min(Ax, Bx) < Fx < max(Ax, Bx):
			print(abs(Ax - Bx) + 2)
		else:
			print(abs(Ax - Bx))
	else:
		print(0)


import math as mt
import sys

def rint():
	return int(sys.stdin.readline())

def rarr(typ):
	return map(typ, sys.stdin.readline().split())

def rmult(typ):
	return map(typ, sys.stdin.readlines().split())

def main(a, b, f):

	def dist(p, q):
		return abs(p[0] - q[0]) + abs(p[1] - q[1])
	ans = dist(a, b)
	if a[0] == b[0] == f[0] or a[1] == b[1] == f[1]:
		if dist(a, f) + dist(b, f) == ans:
			ans += 2
	return ans
t = rint()
for _ in range(t):
	input()
	a = tuple(rarr(int))
	b = tuple(rarr(int))
	f = tuple(rarr(int))
	print(main(a, b, f))


n = int(input())
for i in range(n):
	A = input()
	(x, y) = map(int, input().split())
	(a, b) = input().split()
	(fx, fy) = input().split()
	x = int(x)
	y = int(y)
	a = int(a)
	b = int(b)
	fx = int(fx)
	fy = int(fy)
	if b < y:
		m = b
		b = y
		y = m
	if a < x:
		m = a
		a = x
		x = m
	l = abs(y - b) + abs(x - a)
	if fx == x and fx == a and (fy < b) and (fy > y):
		l = l + 2
	elif fy == y and fy == b and (fx < a) and (fx > x):
		l = l + 2
	print(l)


T = int(input())
for case in range(T):
	a = input()
	(x, y) = list(map(int, input().split()))
	(i, j) = list(map(int, input().split()))
	(dx, dy) = list(map(int, input().split()))
	if i != x and j != y:
		print(abs(x - i) + abs(y - j))
	elif i == x and i == dx:
		maxi = max(y, j)
		mini = min(y, j)
		if mini < dy < maxi:
			print(maxi - mini + 2)
		else:
			print(maxi - mini)
	elif j == y and j == dy:
		maxi = max(x, i)
		mini = min(x, i)
		if mini < dx < maxi:
			print(maxi - mini + 2)
		else:
			print(maxi - mini)
	else:
		print(abs(x - i) + abs(y - j))


for _ in range(int(input())):
	input()
	(aa, ab) = map(int, input().split())
	(ba, bb) = map(int, input().split())
	(fa, fb) = map(int, input().split())
	if ab == bb == fb and (aa < fa < ba or ba < fa < aa):
		print(abs(aa - ba) + abs(ab - bb) + 2)
	elif aa == ba == fa and (ab < fb < bb or bb < fb < ab):
		print(abs(aa - ba) + abs(ab - bb) + 2)
	else:
		print(abs(aa - ba) + abs(ab - bb))


N = int(input())
arr = []
coord = []
coord = [[0 for j in range(2)] for i in range(3)]
for i in range(N):
	arr.append(0)
for i in range(N):
	input()
	(coord[0][0], coord[0][1]) = map(int, input().split())
	(coord[1][0], coord[1][1]) = map(int, input().split())
	(coord[2][0], coord[2][1]) = map(int, input().split())
	arr[i] = abs(coord[1][0] - coord[0][0]) + abs(coord[1][1] - coord[0][1])
	if coord[0][0] == coord[1][0] and coord[1][0] == coord[2][0] and (abs(coord[0][1] - coord[2][1]) + abs(coord[2][1] - coord[1][1]) == abs(coord[1][1] - coord[0][1])) or (coord[0][1] == coord[1][1] and coord[1][1] == coord[2][1] and (abs(coord[0][0] - coord[2][0]) + abs(coord[2][0] - coord[1][0]) == abs(coord[1][0] - coord[0][0]))):
		arr[i] += 2
for i in range(N):
	print(arr[i])


t = int(input())
for i in range(t):
	s = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	c = 0
	if xa == xb == xf and (ya < yf < yb or ya > yf > yb):
		c = 2
	if ya == yb == yf and (xa < xf < xb or xa > xf > xb):
		c = 2
	print(abs(xa - xb) + abs(ya - yb) + c)


def ques1():
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	total_steps = 0
	total_steps += abs(x1 - x2) + abs(y1 - y2)
	if x1 == x3 and x2 == x3:
		min_y = min(y1, y2)
		max_y = max(y1, y2)
		if y3 > min_y and y3 < max_y:
			total_steps += 2
	elif y1 == y3 and y2 == y3:
		min_x = min(x1, x2)
		max_x = max(x1, x2)
		if x3 > min_x and x3 < max_x:
			total_steps += 2
	return total_steps
number_of_testcases = int(input())
input()
for i in range(number_of_testcases):
	print(ques1())
	if i < number_of_testcases - 1:
		input()


import math
import itertools
t = int(input())
for _ in range(t):
	input()
	(x_a, y_a) = map(int, input().split())
	(x_b, y_b) = map(int, input().split())
	(x_f, y_f) = map(int, input().split())
	if x_a == x_b and x_a != x_f:
		print(abs(y_a - y_b))
	elif y_a == y_b and y_a != y_f:
		print(abs(x_a - x_b))
	elif x_a == x_b and x_a == x_f:
		if y_a > y_f > y_b or y_b > y_f > y_a:
			print(abs(y_a - y_b) + 2)
		else:
			print(abs(y_a - y_b))
	elif y_a == y_b and y_a == y_f:
		if x_a > x_f > x_b or x_b > x_f > x_a:
			print(abs(x_a - x_b) + 2)
		else:
			print(abs(x_a - x_b))
	elif x_a != x_b and y_a != y_b:
		print(abs(x_a - x_b) + abs(y_a - y_b))


import math

def getList(method=int):
	return list(map(method, input().split()))

def getInt():
	return int(input())
for _ in range(getInt()):
	input()
	(xa, ya) = getList()
	(xb, yb) = getList()
	(xf, yf) = getList()
	ans = abs(xa - xb) + abs(ya - yb)
	if xa == xb == xf and min(ya, yb) < yf < max(ya, yb) or (ya == yb == yf and min(xa, xb) < xf < max(xa, xb)):
		ans += 2
	print(ans)


def path():
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(fx, fy) = map(int, input().split())
	if (ax == bx and bx == fx) and (fy > min(ay, by) and fy < max(ay, by)):
		return abs(ay - by) + 2
	elif (by == ay and by == fy) and (fx > min(ax, bx) and fx < max(ax, bx)):
		return abs(ax - bx) + 2
	else:
		return abs(ay - by) + abs(ax - bx)
for _ in range(int(input())):
	empty = str(input())
	print(path())


import sys
from os import path
import collections
from collections import defaultdict
import math
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = int(sys.stdin.readline().rstrip())
while t > 0:
	t -= 1
	m = input()
	(a1, a2) = map(int, sys.stdin.readline().rstrip().split())
	(b1, b2) = map(int, sys.stdin.readline().rstrip().split())
	(f1, f2) = map(int, sys.stdin.readline().rstrip().split())
	c = 0
	if a1 == b1 == f1:
		if b2 <= f2 <= a2 or a2 <= f2 <= b2:
			c = abs(b2 - a2) + 2
		else:
			c = abs(b2 - a2)
	elif a2 == b2 == f2:
		if b1 <= f1 <= a1 or a1 <= f1 <= b1:
			c = abs(b1 - a1) + 2
		else:
			c = abs(b1 - a1)
	else:
		c = abs(a1 - b1) + abs(a2 - b2)
	print(c)


t = int(input())
input()
for tests in range(t):
	a = [int(i) for i in input().split(' ')]
	b = [int(i) for i in input().split(' ')]
	f = [int(i) for i in input().split(' ')]
	steps = abs(a[0] - b[0]) + abs(a[1] - b[1])
	if a[0] == b[0] and a[0] == f[0] and (a[1] < f[1] < b[1] or b[1] < f[1] < a[1]):
		steps += 2
	if a[1] == b[1] and a[1] == f[1] and (a[0] < f[0] < b[0] or b[0] < f[0] < a[0]):
		steps += 2
	print(steps)
	if tests < t - 1:
		input()


n = int(input())
for i in range(n):
	vide = input()
	debut = list(map(int, input().split()))
	fin = list(map(int, input().split()))
	obstacle = list(map(int, input().split()))
	l = abs(fin[1] - debut[1]) + abs(fin[0] - debut[0])
	if fin[1] == debut[1] == obstacle[1] and (fin[0] < obstacle[0] < debut[0] or fin[0] > obstacle[0] > debut[0]):
		l += 2
	elif fin[0] == debut[0] == obstacle[0] and (fin[1] < obstacle[1] < debut[1] or fin[1] > obstacle[1] > debut[1]):
		l += 2
	print(l)


for _ in range(int(input())):
	n = input()
	(xa, xb) = map(int, input().split())
	(ya, yb) = map(int, input().split())
	(za, zb) = map(int, input().split())
	st = abs(xa - ya) + abs(yb - xb)
	if xa == ya and xa == za and (xb < zb < yb or yb < zb < xb):
		st += 2
	if xb == yb and xb == zb and (xa < za < ya or ya < za < xa):
		st += 2
	print(st)


T = int(input())
for tc in range(1, T + 1):
	blank = input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	if x1 == x2 == x3:
		if y1 > y2 and y2 <= y3 <= y1:
			print(y1 - y2 + 2)
		elif y1 < y2 and y1 <= y3 <= y2:
			print(y2 - y1 + 2)
		else:
			print(abs(y1 - y2))
	elif y1 == y2 == y3:
		if x1 > x2 and x2 <= x3 <= x1:
			print(x1 - x2 + 2)
		elif x1 < x2 and x1 <= x3 <= x2:
			print(x2 - x1 + 2)
		else:
			print(abs(x1 - x2))
	else:
		print(abs(x1 - x2) + abs(y1 - y2))


test = int(input())
for _ in range(test):
	space = input()
	(a1, a2) = map(int, input().split())
	(b1, b2) = map(int, input().split())
	(f1, f2) = map(int, input().split())
	ans = 0
	if a1 == b1 == f1:
		if a2 < f2 < b2 or b2 < f2 < a2:
			ans = abs(a2 - b2) + 2
		else:
			ans = abs(a2 - b2)
	elif a2 == b2 == f2:
		if a1 < f1 < b1 or b1 < f1 < a1:
			ans = abs(a1 - b1) + 2
		else:
			ans = abs(a1 - b1)
	else:
		ans = abs(a1 - b1) + abs(a2 - b2)
	print(ans)


import math
t = int(input())
for cs in range(t):
	input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	(x1, x2) = sorted([x1, x2])
	(y1, y2) = sorted([y1, y2])
	dist = abs(x1 - x2) + abs(y1 - y2)
	if any([len(set([x1, x2, x3])) == 1 and y1 <= y3 <= y2, len(set([y1, y2, y3])) == 1 and x1 <= x3 <= x2]):
		dist += 2
	print(dist)


for _ in range(int(input())):
	s = input()
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(fx, fy) = map(int, input().split())
	d = abs(bx - ax) + abs(by - ay)
	if (ax == bx and bx == fx) and min(ay, by) <= fy and (max(ay, by) >= fy):
		d += 2
	if (ay == by and by == fy) and min(ax, bx) <= fx and (max(ax, bx) >= fx):
		d += 2
	print(d)


for _ in ' ' * int(input()):
	blank = input()
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xf, yf) = map(int, input().split())
	dist = abs(xb - xa) + abs(yb - ya)
	if xa == xb == xf and (ya < yf < yb or yb < yf < ya) or (ya == yb == yf and (xa < xf < xb or xb < xf < xa)):
		dist += 2
	print(dist)


t = int(input())
for _ in range(t):
	s = input()
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(e, f) = map(int, input().split())
	if a == c == e:
		if (f - b) * (f - d) < 0:
			print(abs(d - b) + 2)
		else:
			print(abs(d - b))
	elif b == d == f:
		if (a - e) * (c - e) < 0:
			print(abs(a - c) + 2)
		else:
			print(abs(a - c))
	else:
		print(abs(a - c) + abs(b - d))


a = int(input())
e = input()
for i in range(a):
	(a1, a2) = list(map(int, input().split()))
	(b1, b2) = list(map(int, input().split()))
	(f1, f2) = list(map(int, input().split()))
	if i != a - 1:
		e = input()
	if a1 == b1 and f1 == a1 and (f2 > min(a2, b2) and f2 < max(a2, b2)):
		print(abs(a1 - b1) + abs(a2 - b2) + 2)
	elif a2 == b2 and f2 == b2 and (f1 > min(a1, b1)) and (f1 < max(a1, b1)):
		print(abs(a1 - b1) + abs(a2 - b2) + 2)
	else:
		print(abs(a1 - b1) + abs(a2 - b2))


def func():
	c = int(input())
	k = []
	for i in range(c):
		input()
		m = []
		m.append(input())
		m.append(input())
		m.append(input())
		ax = int(str(m[0]).split()[0])
		ay = int(str(m[0]).split()[1])
		bx = int(str(m[1]).split()[0])
		by = int(str(m[1]).split()[1])
		fx = int(str(m[2]).split()[0])
		fy = int(str(m[2]).split()[1])
		if ax == bx:
			if fx == ax:
				if ay < by and fy < by and (fy > ay):
					k.append(abs(by - ay) + 2)
				elif ay > by and fy < ay and (fy > by):
					k.append(abs(by - ay) + 2)
				else:
					k.append(abs(by - ay))
			else:
				k.append(abs(by - ay))
		elif ay == by:
			if fy == ay:
				if ax < bx and fx < bx and (fx > ax):
					k.append(abs(bx - ax) + 2)
				elif ax > bx and fx < ax and (fx > bx):
					k.append(abs(bx - ax) + 2)
				else:
					k.append(abs(bx - ax))
			else:
				k.append(abs(bx - ax))
		elif ay != by and ax != bx:
			k.append(abs(bx - ax) + abs(by - ay))
	for i in range(c):
		print(k[i])
func()


import math
inp = int(input())
for _ in range(inp):
	input()
	(xa, ya) = map(int, input().split(' '))
	(xb, yb) = map(int, input().split(' '))
	(xc, yc) = map(int, input().split(' '))
	dist = abs(xa - xb) + abs(ya - yb)
	if math.sqrt((xa - xb) ** 2 + (ya - yb) ** 2) >= math.sqrt((xa - xc) ** 2 + (ya - yc) ** 2) and math.sqrt((xa - xb) ** 2 + (ya - yb) ** 2) >= math.sqrt((xb - xc) ** 2 + (yb - yc) ** 2):
		if xc == xa and xc == xb or (yc == ya and yc == yb):
			dist += 2
			print(dist)
		else:
			print(dist)
	else:
		print(dist)


import heapq, math
from collections import defaultdict, deque
from os import getcwd
import sys, os.path
if os.path.exists('D:\\CP\\programs\\input.txt'):
	sys.stdout = open('D:\\CP\\programs\\output.txt', 'w')
	sys.stdin = open('D:\\CP\\programs\\input.txt', 'r')
input = sys.stdin.readline
test = int(input())
for _ in range(test):
	input()
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	dis = abs(x1 - x2) + abs(y1 - y2)
	if x1 == x2 and x2 == x3:
		if y3 > min(y1, y2) and y3 < max(y1, y2):
			dis += 2
	elif y1 == y2 and y2 == y3:
		if x3 > min(x1, x2) and x3 < max(x1, x2):
			dis += 2
	print(dis)


import sys

def rl():
	return sys.stdin.readline().strip()

def rl_types(types):
	str_list = [x for x in sys.stdin.readline().strip().split(' ')]
	return [types[i](str_list[i]) for i in range(len(str_list))]

def pr(something):
	sys.stdout.write(str(something) + '\n')

def pra(array):
	sys.stdout.write(' '.join([str(x) for x in array]) + '\n')

def solve(array):
	return array
NT = int(rl())
for ti in range(NT):
	rl()
	(ax, ay) = [int(x) for x in rl().split(' ')]
	(bx, by) = [int(x) for x in rl().split(' ')]
	(fx, fy) = [int(x) for x in rl().split(' ')]
	(dx, dy) = (abs(bx - ax), abs(by - ay))
	dist = dx + dy
	if ax < fx < bx and ay == by and (ay == fy) or (ax > fx > bx and ay == by and (ay == fy)) or (ax == bx and ax == fx and (ay < fy < by)) or (ax == bx and ax == fx and (ay > fy > by)):
		dist += 2
	pr(dist)