We have three stones at points (0, 0), (1,0), and (0,1) on a two-dimensional plane.
These three stones are said to form an L when they satisfy the following conditions:
 - Each of the stones is at integer coordinates.
 - Each of the stones is adjacent to another stone. (That is, for each stone, there is another stone whose distance from that stone is 1.)
 - The three stones do not lie on the same line.
Particularly, the initial arrangement of the stone - (0, 0), (1,0), and (0,1) - forms an L.
You can do the following operation any number of times: choose one of the stones and move it to any position. However, after each operation, the stones must form an L.
You want to do as few operations as possible to put stones at points (ax, ay), (bx, by), and (cx, cy). How many operations do you need to do this?
It is guaranteed that the desired arrangement of stones - (ax, ay), (bx, by), and (cx, cy) - forms an L. Under this condition, it is always possible to achieve the objective with a finite number of operations.
You will be given T cases of this problem. Solve each of them.

-----Notes-----
We assume that the three stones are indistinguishable. For example, the stone that is initially at point (0,0) may be at any of the points (ax, ay), (bx, by), and (cx, cy) in the end.

-----Constraints-----
 - 1 \leq T \leq 10^3
 - |ax|,|ay|,|bx|,|by|,|cx|,|cy| \leq 10^9
 - The desired arrangement of stones - (ax, ay), (bx, by), and (cx, cy) - forms an L.

-----Input-----
Input is given from Standard Input in the following format:
T
\text{case}_1
\vdots
\text{case}_T

Each case is in the following format:
ax ay bx by cx cy

-----Output-----
Print T values. The i-th value should be the minimum number of operations for \text{case}_i.

-----Sample Input-----
1
3 2 2 2 2 1

-----Sample Output-----
4

Let us use # to represent a stone.
You can move the stones to the specified positions with four operations, as follows:
....    ....    ....    ..#.    ..##
#... -> ##.. -> .##. -> .##. -> ..#.
##..    .#..    .#..    ....    ....

Source: atcoder | Difficulty: HARD


Solutions:
import sys
input = sys.stdin.readline

def solve(ax, ay, bx, by, cx, cy):
	x = ax + bx + cx
	y = ay + by + cy
	x -= x // 3 + 1
	y -= y // 3 + 1
	if x == y:
		return x if 0 <= x <= 1 else abs(x) + 1
	else:
		return max(abs(x), abs(y))
T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	print(solve(ax, ay, bx, by, cx, cy))


for _ in range(int(input())):
	Z = list(map(int, input().split()))
	X = sum(Z[::2])
	Y = sum(Z[1::2])
	if sum(Z[:4]) % 2 == 0:
		X += Z[4]
		Y += Z[5]
	elif sum(Z[2:]) % 2 == 0:
		X += Z[0]
		Y += Z[1]
	else:
		X += Z[2]
		Y += Z[3]
	if X != Y:
		print(max(abs((X - 1) // 2), abs((Y - 1) // 2)))
	elif X == 1 and Y == 1:
		print(0)
	elif X == 3 and Y == 3:
		print(1)
	else:
		print(max(abs((X - 1) // 2), abs((Y - 1) // 2)) + 1)


(T, *I) = map(int, open(0).read().split())
for (ax, ay, bx, by, cx, cy) in zip(*[iter(I)] * 6):
	x = ax + bx + cx
	y = ay + by + cy
	dx = abs(x - x // 3 - 1)
	dy = abs(y - y // 3 - 1)
	print(max(dx, dy) + (x == y and x // 3 != 0))


T = int(input())

def calc(ax, ay, bx, by, cx, cy):
	GL = min(ax, bx, cx)
	GU = min(ay, by, cy)
	xcnt = {}
	for x in (ax, bx, cx):
		xcnt[x] = xcnt.get(x, 0) + 1
	ycnt = {}
	for y in (ay, by, cy):
		ycnt[y] = ycnt.get(y, 0) + 1
	if GL == 0 and GU == 0:
		if xcnt[0] == 2 and ycnt[0] == 2:
			ret = 0
		else:
			ret = 1
	else:
		ret = int(GL > 0)
		ret += min(abs(GL), abs(GU)) * 2
		if abs(GU) > abs(GL):
			ret += 1
		ret += max(0, abs(abs(GU) - abs(GL)) * 2 - 1)
		if abs(GU) >= abs(GL):
			if GU > 0:
				if ycnt[GU] == 1:
					ret += 1
			elif ycnt[GU] == 2:
				ret += 1
		elif GL > 0:
			if xcnt[GL] == 1:
				ret += 1
		elif xcnt[GL] == 2:
			ret += 1
	return ret
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	ans0 = calc(ax, ay, bx, by, cx, cy)
	ans1 = calc(ay, ax, by, bx, cy, cx)
	ans = min(ans0, ans1)
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c, d, e, f) = list(map(int, input().split()))
	x = -max({a, c, e}) + a + c + e
	y = -max({b, d, f}) + b + d + f
	print(max(abs(x), abs(y)) + (x == y and x and (x != 1)))


import sys
from collections import deque
T = int(input())

def ku_state(p1, p2, p3):
	xb = min([p[0] for p in [p1, p2, p3]])
	yb = min([p[1] for p in [p1, p2, p3]])
	s = set([(p[0] - xb, p[1] - yb) for p in [p1, p2, p3]])
	if len(s) != 3 or max([x[0] for x in s]) != 1 or max([x[1] for x in s]) != 1:
		return None
	if (1, 1) not in s:
		return 0
	elif (1, 0) not in s:
		return 1
	elif (0, 0) not in s:
		return 2
	elif (0, 1) not in s:
		return 3
	else:
		return None
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	ps = [(ax, ay), (bx, by), (cx, cy)]
	ku = ku_state(*ps)
	xb = min(ax, bx, cx)
	yb = min(ay, by, cy)
	xd = int(abs(xb + 0.5))
	yd = int(abs(yb + 0.5))
	if xb == 0 and yb == 0:
		print(int(ku != 0))
		continue
	if ku == 0:
		ans = max(abs(xb), abs(yb)) * 2
		if xb == yb:
			ans += 1
	elif ku == 1:
		ans = max(abs(xb) * 2, 2 * yd + 1)
		ans = max(1, ans)
	elif ku == 2:
		if xb == 0 and yb == 0:
			ans = 1
		else:
			ans = max(xd, yd) * 2 + 1
			if xb == yb:
				ans += 1
	elif ku == 3:
		ans = max(abs(yb) * 2, 2 * xd + 1)
		ans = max(1, ans)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	x = ax + bx + cx
	y = ay + by + cy
	if x == 1 and y == 1:
		print(0)
		continue
	if x == 2 and y == 2:
		print(1)
		continue
	if x == y:
		print(abs(x) - abs(x) // 3 + (x < 0))
		continue
	if x < 0:
		x = abs(x)
		x -= x // 3
		x += 1
	else:
		x -= x // 3
	if y < 0:
		y = abs(y)
		y -= y // 3
		y += 1
	else:
		y -= y // 3
	print(max(x, y) - 1)


T = int(input())

def nasu(a, b, c):
	mi = min(a, b, c)
	ma = max(a, b, c)
	f = False
	if mi >= 0:
		f = True
		t = (ma - 1) * 2
		if a + b + c == ma * 2 + mi:
			t += 1
		return (t, f)
	else:
		t = -mi * 2 - 1
		if a + b + c == mi * 2 + ma:
			t += 1
		return (t, f)

def main():
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	ans = 0
	(x, xf) = nasu(ax, bx, cx)
	(y, yf) = nasu(ay, by, cy)
	ans += max(x, y)
	if xf and yf and (x == y) and (x >= 2):
		ans += 1
	if not xf and (not yf) and (x == y) and (x >= 1):
		ans += 1
	print(ans)
for i in range(T):
	main()


def solve(*args):
	sx = sum(args[::2])
	sy = sum(args[1::2])
	dx = sx - sx // 3 - 1
	dy = sy - sy // 3 - 1
	ans = max(abs(dx), abs(dy))
	if sx == sy and sx // 3 != 0:
		ans += 1
	return ans
t = int(input())
for i in range(t):
	print(solve(*list(map(int, input().split()))))


def get_center(ps):
	(xs, ys) = list(zip(*ps))
	(xs, ys) = (list(xs), list(ys))
	xs.sort()
	ys.sort()
	return (xs[1], ys[1])

def get_shape(ps):
	(xs, ys) = list(zip(*ps))
	(xs, ys) = (list(xs), list(ys))
	xs.sort()
	ys.sort()
	if xs[0] == xs[1] and ys[0] == ys[1]:
		return 0
	elif xs[0] == xs[1] and ys[1] == ys[2]:
		return 1
	elif xs[1] == xs[2] and ys[0] == ys[1]:
		return 2
	else:
		return 3
t = int(input())
for _ in range(t):
	(x1, y1, x2, y2, x3, y3) = map(int, input().split())
	ps = [(x1, y1), (x2, y2), (x3, y3)]
	(cx, cy) = get_center(ps)
	shape = get_shape(ps)
	if cx == 0 and cy == 0:
		if shape == 0:
			print(0)
		elif shape == 1:
			print(1)
		elif shape == 2:
			print(1)
		else:
			print(2)
	elif cx == 1 and cy == 1:
		if shape == 0:
			print(3)
		elif shape == 1:
			print(2)
		elif shape == 2:
			print(2)
		else:
			print(1)
	elif cx == cy:
		if cx > 0:
			if shape == 0:
				print(2 * cx + 1)
			else:
				print(2 * cx)
		elif shape == 3:
			print(2 - 2 * cx)
		else:
			print(1 - 2 * cx)
	elif abs(cx) > abs(cy) and cx > 0:
		if shape == 0 or shape == 1:
			print(cx * 2)
		else:
			print(cx * 2 - 1)
	elif abs(cx) >= abs(cy) and cx < 0:
		if shape == 0 or shape == 1:
			print(-cx * 2)
		else:
			print(-cx * 2 + 1)
	elif abs(cx) < abs(cy) and cy > 0:
		if shape == 0 or shape == 2:
			print(cy * 2)
		else:
			print(cy * 2 - 1)
	elif shape == 0 or shape == 2:
		print(-cy * 2)
	else:
		print(-cy * 2 + 1)


def form(ax, ay, bx, by, cx, cy):
	P = [(ax, ay), (bx, by), (cx, cy)]
	Q = [(0, 0)]
	for i in range(3):
		(x0, y0) = (P[i][0], P[i][1])
		(x1, y1) = (P[(i - 1) % 3][0], P[(i - 1) % 3][1])
		(x2, y2) = (P[(i + 1) % 3][0], P[(i + 1) % 3][1])
		if abs(x0 - x1) + abs(y0 - y1) == 1 and abs(x0 - x2) + abs(y0 - y2) == 1:
			Q.append((x1 - x0, y1 - y0))
			Q.append((x2 - x0, y2 - y0))
			break
	else:
		return -1
	Q.sort()
	if Q == [(0, 0), (0, 1), (1, 0)]:
		return (11, x0, y0)
	elif Q == [(-1, 0), (0, -1), (0, 0)]:
		return (0, x0, y0)
	elif Q == [(0, -1), (0, 0), (1, 0)]:
		return (10, x0, y0)
	elif Q == [(-1, 0), (0, 0), (0, 1)]:
		return (1, x0, y0)

def move(f, x, y):
	if f == 11:
		return [(0, x + 1, y + 1), (10, x, y), (1, x, y), (10, x, y + 1), (0, x, y + 1), (1, x + 1, y), (0, x + 1, y)]
	elif f == 0:
		return [(11, x - 1, y - 1), (1, x, y), (10, x, y), (1, x, y - 1), (11, x, y - 1), (10, x - 1, y), (11, x - 1, y)]
	elif f == 10:
		return [(1, x + 1, y - 1), (11, x, y), (0, x, y), (11, x, y - 1), (1, x, y - 1), (0, x + 1, y), (1, x + 1, y)]
	elif f == 1:
		return [(10, x - 1, y + 1), (0, x, y), (11, x, y), (0, x, y + 1), (10, x, y + 1), (11, x - 1, y), (10, x - 1, y)]

def same_angle(f0, x0, y0, f1, x1, y1):
	if x1 >= x0 and y1 >= y0 and (f0 == f1 == 11 or f0 == f1 == 0):
		return 1
	if x1 < x0 and y1 >= y0 and (f0 == f1 == 1 or f0 == f1 == 10):
		return 1
	if x1 >= x0 and y1 < y0 and (f0 == f1 == 1 or f0 == f1 == 10):
		return 1
	if x1 < x0 and y1 < y0 and (f0 == f1 == 11 or f0 == f1 == 0):
		return 1
	return 0

def next_set(f, x, y):
	P = [(f, x, y)]
	res = [(f, x, y, 0)]
	for t in range(2):
		Q = []
		for (f, x, y) in P:
			Q.extend(move(f, x, y))
		P = Q
		for (f, x, y) in P:
			res.append((f, x, y, t + 1))
	return res

def main():
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	res = float('inf')
	(f, x, y) = form(ax, ay, bx, by, cx, cy)
	for (f0, x0, y0, time0) in next_set(11, 0, 0):
		for (f1, x1, y1, time1) in next_set(f, x, y):
			if same_angle(f0, x0, y0, f1, x1, y1) and max(abs(x0 - x1), abs(y0 - y1)) > 0:
				continue
			if f0 == f1:
				tmp = max(abs(x0 - x1), abs(y0 - y1)) * 2 + (time0 + time1)
				if res > tmp:
					res = tmp
	print(res)
T = int(input())
for _ in range(T):
	main()


for t in range(int(input())):
	(a, b, c, d, e, f) = map(int, input().split())
	g = a + c + e - max([a, c, e])
	h = b + d + f - max([b, d, f])
	print(max([abs(g), abs(h)]) + (g * (g - 1) and g == h))


from collections import deque

def di(x, y, z, w):
	return abs(x - z) + abs(y - w)

def convert(a, b, c, d, e, f):
	if di(c, d, a, b) == 1 and di(c, d, e, f) == 1:
		(a, b, c, d) = (c, d, a, b)
	elif di(e, f, c, d) == 1 and di(e, f, a, b) == 1:
		(a, b, e, f) = (e, f, a, b)
	if c == a:
		if d == b + 1:
			if e == a + 1:
				(a, b, c, d, e, f) = (a, b, a + 1, b, a, b + 1)
			else:
				(a, b, c, d, e, f) = (a, b, a, b + 1, a - 1, b)
		elif e == a + 1:
			(a, b, c, d, e, f) = (a, b, a + 1, b, a, b - 1)
		else:
			(a, b, c, d, e, f) = (a, b, a - 1, b, a, b - 1)
	elif c == a + 1:
		if f == b + 1:
			(a, b, c, d, e, f) = (a, b, a + 1, b, a, b + 1)
		else:
			(a, b, c, d, e, f) = (a, b, a + 1, b, a, b - 1)
	elif f == b + 1:
		(a, b, c, d, e, f) = (a, b, a, b + 1, a - 1, b)
	else:
		(a, b, c, d, e, f) = (a, b, a - 1, b, a, b - 1)
	return (a, b, c, d, e, f)
dist = {}
pos = (0, 0, 1, 0, 0, 1)
deq = deque([pos])
dist[pos] = 0
while deq:
	(a, b, c, d, e, f) = deq.popleft()
	D = dist[a, b, c, d, e, f]
	if D == 10:
		continue
	(nx, ny) = (1, 1)
	if (c, d) == (a + 1, b) and (e, f) == (a + 1, b):
		(nx, ny) = (1, 1)
	elif (c, d) == (a, b + 1) and (e, f) == (a - 1, b):
		(nx, ny) = (-1, 1)
		(c, d, e, f) = (e, f, c, d)
	elif (c, d) == (a - 1, b) and (e, f) == (a, b - 1):
		(nx, ny) = (-1, -1)
	elif (c, d) == (a + 1, b) and (e, f) == (a, b - 1):
		(nx, ny) = (1, -1)
	if convert(a + nx, b + ny, e, f, c, d) not in dist:
		dist[convert(a + nx, b + ny, e, f, c, d)] = D + 1
		deq.append(convert(a + nx, b + ny, e, f, c, d))
	if convert(e, f, e - nx, f, a, b) not in dist:
		dist[convert(e, f, e - nx, f, a, b)] = D + 1
		deq.append(convert(e, f, e - nx, f, a, b))
	if convert(a, b, e, f, a - nx, b) not in dist:
		dist[convert(a, b, e, f, a - nx, b)] = D + 1
		deq.append(convert(a, b, e, f, a - nx, b))
	if convert(e, f, e + nx, f, a, b) not in dist:
		dist[convert(e, f, e + nx, f, a, b)] = D + 1
		deq.append(convert(e, f, e + nx, f, a, b))
	if convert(c, d, a, b, c, d - ny) not in dist:
		dist[convert(c, d, a, b, c, d - ny)] = D + 1
		deq.append(convert(c, d, a, b, c, d - ny))
	if convert(a, b, c, d, a, b - ny) not in dist:
		dist[convert(a, b, c, d, a, b - ny)] = D + 1
		deq.append(convert(a, b, c, d, a, b - ny))
	if convert(c, d, c, d + ny, a, b) not in dist:
		dist[convert(c, d, c, d + ny, a, b)] = D + 1
		deq.append(convert(c, d, c, d + ny, a, b))
import sys
input = sys.stdin.readline
ans = []
for _ in range(int(input())):
	(a, b, c, d, e, f) = map(int, input().split())
	if di(c, d, a, b) == 1 and di(c, d, e, f) == 1:
		(a, b, c, d) = (c, d, a, b)
	elif di(e, f, c, d) == 1 and di(e, f, a, b) == 1:
		(a, b, e, f) = (e, f, a, b)
	if c == a:
		if d == b + 1:
			if e == a + 1:
				(a, b, c, d, e, f) = (a, b, a + 1, b, a, b + 1)
			else:
				(a, b, c, d, e, f) = (a, b, a, b + 1, a - 1, b)
		elif e == a + 1:
			(a, b, c, d, e, f) = (a, b, a + 1, b, a, b - 1)
		else:
			(a, b, c, d, e, f) = (a, b, a - 1, b, a, b - 1)
	elif c == a + 1:
		if f == b + 1:
			(a, b, c, d, e, f) = (a, b, a + 1, b, a, b + 1)
		else:
			(a, b, c, d, e, f) = (a, b, a + 1, b, a, b - 1)
	elif f == b + 1:
		(a, b, c, d, e, f) = (a, b, a, b + 1, a - 1, b)
	else:
		(a, b, c, d, e, f) = (a, b, a - 1, b, a, b - 1)
	res = 10 ** 18
	if (c, d, e, f) == (a + 1, b, a, b + 1):
		if a * b >= 0 and a and (a == b):
			res = 2 * max(abs(a), abs(b)) + 1
		else:
			res = 2 * max(abs(a), abs(b))
	elif (c, d, e, f) == (a, b + 1, a - 1, b):
		if a >= 0 and b >= 0:
			if (a, b) == (0, 0):
				res = 1
			elif b >= a:
				res = 2 * b
			else:
				res = 2 * a - 1
		elif a >= 0 and b < 0:
			if -b >= a:
				res = 2 * -b
			else:
				res = 2 * a - 1
		elif a < 0 and b >= 0:
			if b > -a:
				res = 2 * b
			else:
				res = 2 * -a + 1
		elif -b > -a:
			res = 2 * -b
		else:
			res = 2 * -a + 1
	elif (c, d, e, f) == (a + 1, b, a, b - 1):
		if a >= 0 and b >= 0:
			if (a, b) == (0, 0):
				res = 1
			elif a >= b:
				res = 2 * a
			else:
				res = 2 * b - 1
		elif a >= 0 and b < 0:
			if a > -b:
				res = 2 * a
			else:
				res = 2 * -b + 1
		elif a < 0 and b >= 0:
			if -a >= b:
				res = 2 * -a
			else:
				res = 2 * b - 1
		elif -a > -b:
			res = 2 * -a
		else:
			res = 2 * -b + 1
	elif a >= 0 and b >= 0:
		if (a, b) == (0, 0):
			res = 2
		elif b > a:
			res = 2 * b - 1
		elif a > b:
			res = 2 * a - 1
		elif a == 1:
			res = 1
		else:
			res = 2 * a
	elif a >= 0 and b < 0:
		if -b >= a:
			res = 2 * -b + 1
		else:
			res = 2 * a - 1
	elif a < 0 and b >= 0:
		if -a >= b:
			res = 2 * -a + 1
		else:
			res = 2 * b - 1
	elif a != b:
		res = 2 * max(-a, -b) + 1
	else:
		res = 2 + 2 * abs(a)
	ans.append(res)
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
n = int(input())
C = [list(map(int, input().split())) for i in range(n)]
big = 10 ** 5
l = 7
D = [[[big] * 4 for i in range(l)] for j in range(l)]
mi = 3
D[mi][mi][0] = 0
L = [(0, 1, 1), (1, 0, 3), (1, 1, 2), (0, 1, 2), (1, 0, 2), (0, 0, 3), (0, 0, 1)]
LL = [(0, 1, 1), (1, 0, 3), (1, 1, 2), (0, 1, 2), (1, 0, 2), (0, 0, 3), (0, 0, 1), (0, 0, 0)]
Q = [(mi, mi, 0, 0)]
s = 0
while s < len(Q):
	(x, y, t, d) = Q[s]
	for (nx, ny, nt) in L:
		for k in range(t):
			(nx, ny) = (ny, -nx)
		tt = (nt + t) % 4
		xx = x + nx
		yy = y + ny
		if 0 <= xx < l and 0 <= yy < l and (D[xx][yy][tt] == big):
			D[xx][yy][tt] = d + 1
			Q.append((xx, yy, tt, d + 1))
	s += 1
for i in range(n):
	t = -1
	Xs = [C[i][0], C[i][2], C[i][4]]
	Ys = [C[i][1], C[i][3], C[i][5]]
	Xs.sort()
	Ys.sort()
	MX = max(Xs)
	mX = min(Xs)
	MY = max(Ys)
	mY = min(Ys)
	if Xs[1] == MX and Ys[1] == MY:
		t = 2
	elif Xs[1] == mX and Ys[1] == mY:
		t = 0
	elif Xs[1] == MX and Ys[1] == mY:
		t = 3
	else:
		t = 1
	(cx, cy) = (Xs[1], Ys[1])
	ans = float('inf')
	c = 0
	for (nx, ny, nt) in LL:
		for k in range(t):
			(nx, ny) = (ny, -nx)
		tt = (nt + t) % 4
		xx = cx + nx
		yy = cy + ny
		for j in range(l):
			for k in range(l):
				if tt % 2 == 0 and (j - mi - xx) * (k - mi - yy) <= 0 or (tt % 2 == 1 and (j - mi - xx) * (k - mi - yy) >= 0):
					dx = abs(j - mi - xx)
					dy = abs(k - mi - yy)
					Md = max(dx, dy)
					p = 0
					if c != len(LL) - 1:
						p = 1
					nans = D[j][k][tt] + Md * 2 + p
					ans = min(ans, nans)
		c += 1
	print(ans)


flip = {0: {0: 1, 1: 0, 2: 3, 3: 2}, 1: {0: 3, 1: 2, 2: 1, 3: 0}, 2: {0: 0, 1: 3, 2: 2, 3: 1}}
v = [(0, 0), (1, 0), (1, 1), (0, 1)]

def solve(ax, ay, bx, by, cx, cy):
	points = {(ax, ay), (bx, by), (cx, cy)}
	xm = min(ax, bx, cx)
	ym = min(ay, by, cy)
	rs = 2
	for (i, (vx, vy)) in enumerate(v):
		if (xm + vx, ym + vy) not in points:
			rt = i
			break
	if xm == ym == 0:
		if rt == 2:
			return 0
		else:
			return 1
	if xm < 0:
		xm = -xm
		rs = flip[0][rs]
		rt = flip[0][rt]
	if ym < 0:
		ym = -ym
		rs = flip[1][rs]
		rt = flip[1][rt]
	if xm < ym:
		(xm, ym) = (ym, xm)
		rs = flip[2][rs]
		rt = flip[2][rt]
	if xm == ym:
		res = 2 * xm
		if rs == 2:
			if rt == 0:
				res += 2
			else:
				res += 1
		elif rs in (1, 3):
			if rt in (0, flip[2][rs]):
				res += 1
		elif rt == 0:
			res += 1
	else:
		res = 2 * ym + 1
		res += (xm - ym - 1) * 2
		if rs in (1, 2):
			res += 1
		if rt in (0, 3):
			res += 1
	return res
T = int(input())
ans = []
for i in range(T):
	ans.append(solve(*list(map(int, input().split()))))
print(*ans, sep='\n')


import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy
MOD = 10 ** 9 + 7
T = int(input())
for t in range(T):
	A = list(map(int, input().split()))
	mc = []
	for i in [0, 2, 4]:
		(x, y) = (A[i], A[i + 1])
		c = 0
		if y == x:
			c = 2 * x - 1 if x > 0 else 2 * -x
		elif y == -x + 1:
			c = 2 * x - 2 if x > 0 else 2 * -x
		elif y > x:
			if y > -x + 1:
				c = 2 * y - 2
			else:
				c = 2 * -x - 1
		elif y < x:
			if y > -x + 1:
				c = 2 * x - 2
			else:
				c = 2 * -y - 1
		mc.append(c)
	vmax = max(mc)
	if vmax == 0:
		print(0)
	elif vmax == 1 and mc.count(0) == 2:
		print(1)
	elif mc.count(vmax) == 3:
		print(vmax + 2)
	elif mc.count(vmax) == 2:
		print(vmax + 1)
	elif mc.count(vmax - 1) == 2:
		print(vmax + 1)
	else:
		print(vmax)


import sys
input = sys.stdin.readline
t = int(input())
cases = [tuple(map(int, input().split())) for _ in range(t)]
ans = []
for (ax, ay, bx, by, cx, cy) in cases:
	abcx = ax + bx + cx
	abcy = ay + by + cy
	(xd, xm) = divmod(abcx, 3)
	(yd, ym) = divmod(abcy, 3)
	x = xd * 2 + xm - 1
	y = yd * 2 + ym - 1
	a = max(abs(x), abs(y))
	if x == y and (x >= 2 or x <= -1):
		a += 1
	ans.append(a)
print(*ans, sep='\n')


def coord1d(a, b, c):
	m = max(a, max(b, c))
	ct = 0
	if a == m:
		ct += 1
	if b == m:
		ct += 1
	if c == m:
		ct += 1
	if ct == 1:
		return m * 2 - 1
	else:
		return m * 2

def coord(ax, ay, bx, by, cx, cy):
	newx = coord1d(ax, bx, cx)
	newy = coord1d(ay, by, cy)
	return (newx, newy)
T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	(nx, ny) = coord(ax, ay, bx, by, cx, cy)
	ans = 0
	if nx == ny and (not (nx == 1 or nx == 2)):
		ans = abs(nx - 1) + 1
	else:
		ans = max(abs(nx - 1), abs(ny - 1))
	print(ans)


from collections import defaultdict
T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	X = defaultdict(int)
	Y = defaultdict(int)
	X[ax] += 1
	X[bx] += 1
	X[cx] += 1
	Y[ay] += 1
	Y[by] += 1
	Y[cy] += 1
	x = min(X)
	y = min(Y)
	r = None
	if X[x] == 1 and Y[y] == 1:
		r = 0
	elif X[x] == 1 and Y[y] == 2:
		r = 3
	elif X[x] == 2 and Y[y] == 1:
		r = 1
	else:
		r = 2
	if r == 0:
		ans = max(abs(2 * x + 1), abs(2 * y + 1))
		if x == y and x != 0:
			ans += 1
		print(ans)
	elif r == 1:
		t = None
		ans = None
		if y >= 0:
			t = abs(y) - abs(x)
		else:
			t = abs(y + 1) - abs(x)
		if t >= 0:
			if y >= 0:
				ans = 2 * abs(y) + 1
			else:
				ans = 2 * abs(y) - 1
		else:
			ans = 2 * abs(x)
		print(ans)
	elif r == 3:
		t = None
		ans = None
		if x >= 0:
			t = abs(x) - abs(y)
		else:
			t = abs(x + 1) - abs(y)
		if t >= 0:
			if x >= 0:
				ans = 2 * abs(x) + 1
			else:
				ans = 2 * abs(x) - 1
		else:
			ans = 2 * abs(y)
		print(ans)
	else:
		ans = 2 * max(abs(x), abs(y))
		if x == y and x != 0:
			ans += 1
		print(ans)


from math import floor

def repos(x, y):
	x = int(floor(x)) + int(round(x))
	y = int(floor(y)) + int(round(y))
	return (x, y)
T = int(input())
for _ in range(T):
	(Ax, Ay, Bx, By, Cx, Cy) = list(map(int, input().split()))
	x = (Ax + Bx + Cx) / 3
	y = (Ay + By + Cy) / 3
	(x, y) = repos(x, y)
	if x == y:
		if x == 0:
			print(0)
		elif x == 1:
			print(1)
		else:
			ans = abs(x) + 1
			print(ans)
	else:
		ans = max(abs(x), abs(y))
		print(ans)


abs = lambda x: max(x, -x)
t = int(input())
for i in range(t):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	x = ax + bx + cx
	y = ay + by + cy
	xv = x // 3
	xp = x % 3
	yv = y // 3
	yp = y % 3
	nx = xv * 2 + xp - 1
	ny = yv * 2 + yp - 1
	if nx == ny:
		if nx == 1:
			print(1)
		elif nx == 0:
			print(0)
		else:
			print(abs(nx) + 1)
	else:
		print(max(abs(nx), abs(ny)))


import sys
from sys import stdin
TT = int(stdin.readline())
t0 = tuple(sorted([(0, 0), (0, 1), (1, 0)]))
t1 = tuple(sorted([(0, 0), (0, 1), (1, 1)]))
t2 = tuple(sorted([(0, 1), (1, 0), (1, 1)]))
t3 = tuple(sorted([(0, 0), (1, 0), (1, 1)]))
for loop in range(TT):
	(ax, ay, bx, by, cx, cy) = list(map(int, stdin.readline().split()))
	mx = min(ax, bx, cx)
	my = min(ay, by, cy)
	ox = 2 * mx
	oy = 2 * my
	setz = tuple(sorted([(ax - mx, ay - my), (bx - mx, by - my), (cx - mx, cy - my)]))
	if setz == t0:
		ox += 0
		oy += 0
	elif setz == t1:
		ox += 0
		oy += 1
	elif setz == t2:
		ox += 1
		oy += 1
	else:
		ox += 1
		oy += 0
	if ox != oy:
		print(abs(ox) + abs(oy) - min(abs(ox), abs(oy)))
	elif 0 <= ox <= 1:
		print(ox)
	else:
		print(abs(ox) + abs(oy) - min(abs(ox), abs(oy)) + 1)


def solve(x, y, xd, yd):
	if x + y > 0:
		if x - y > 0:
			return 2 * x + (xd == 1)
		elif x - y < 0:
			return 2 * y + (yd == 1)
		else:
			return 1 + 2 * x + (xd == 1 and yd == 1)
	elif x + y < 0:
		if x - y > 0:
			return -y * 2 - 1 + (yd == 2)
		elif x - y < 0:
			return -x * 2 - 1 + (xd == 2)
		else:
			return -2 * x + (xd == 2 and yd == 2)
	elif x - y > 0:
		return 2 * x + (xd == 1)
	elif x - y < 0:
		return -2 * x + (yd == 1)
	elif xd == 2 and yd == 2:
		return 0
	else:
		return 1

def main():
	t = int(input())
	ans_list = []
	for i in range(t):
		(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
		(x, y) = (min(ax, bx, cx), min(ay, by, cy))
		xd = (ax == x) + (bx == x) + (cx == x)
		yd = (ay == y) + (by == y) + (cy == y)
		ans_list.append(solve(x, y, xd, yd))
	for i in range(t):
		print(ans_list[i])
main()


import sys
readline = sys.stdin.readline
read = sys.stdin.read

def solve1(a, b, c, d, e, f, cx, cy, x, y):
	if x == y:
		if x == 0:
			if cx == cy == 0:
				return 0
			else:
				return 1
		elif cx == cy == x + 1:
			return 2 * x + 2
		else:
			return 2 * x + 1
	elif x < y:
		if cy == y:
			return 2 * y
		else:
			return 2 * y + 1
	elif cx == x:
		return 2 * x
	else:
		return 2 * x + 1

def solve2(a, b, c, d, e, f):
	cx = sorted([a, c, e])[1]
	cy = sorted([b, d, f])[1]
	x = min(a, c, e)
	y = min(b, d, f)
	if x > y:
		if cx == x:
			return 2 * x
		else:
			return 2 * x + 1
	elif cy == y:
		return 2 * y + 1
	else:
		return 2 * y + 2

def solve3(a, b, c, d, e, f):
	cx = sorted([a, c, e])[1]
	cy = sorted([b, d, f])[1]
	x = min(a, c, e)
	y = min(b, d, f)
	if x != y:
		v = max(x, y)
		if cx == v + 1 or cy == v + 1:
			return 2 * (v + 1)
		else:
			return 2 * (v + 1) - 1
	elif cx == cy == x + 1:
		return 2 * (x + 1) + 1
	else:
		return 2 * (x + 1)

def solve():
	(a, b, c, d, e, f) = list(map(int, readline().split()))
	cx = sorted([a, c, e])[1]
	cy = sorted([b, d, f])[1]
	x = min(a, c, e)
	y = min(b, d, f)
	if x >= 0 and y >= 0:
		return (solve1(a, b, c, d, e, f, cx, cy, x, y), 1)
	elif x >= 0:
		return (solve2(a, -b, c, -d, e, -f), 2)
	elif y >= 0:
		return (solve2(b, -a, d, -c, f, -e), 22)
	else:
		return (solve3(-a, -b, -c, -d, -e, -f), 3)
T = int(readline())
for _ in range(T):
	print(solve()[0])


t = int(input())
for _ in range(t):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	(x, y) = (ax + bx + cx, ay + by + cy)
	if x > 0:
		x = x - x // 3 - 1
	else:
		x = x + (2 - x) // 3 - 1
	if y > 0:
		y = y - y // 3 - 1
	else:
		y = y + (2 - y) // 3 - 1
	if x == y == 0:
		print(0)
	elif x == y == 1:
		print(1)
	else:
		print(max(x, -x, y, -y) + int(x == y))


def solve(x, y):
	x = x - x // 3 if x > 0 else x + (2 - x) // 3
	y = y - y // 3 if y > 0 else y + (2 - y) // 3
	x -= 1
	y -= 1
	if (x, y) == (0, 0):
		return 0
	if (x, y) == (1, 1):
		return 1
	return max(abs(x), abs(y)) + (1 if x == y else 0)
T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	print(solve(ax + bx + cx, ay + by + cy))


exec('a=list(map(int,input().split()));g=sum(a[::2])-max(a[::2]);h=sum(a[1::2])-max(a[1::2]);print(max([abs(g),abs(h)])+(g*(g-1)and g==h));' * int(input()))


def main():
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	min_y = min(ay, by, cy)
	min_x = min(ax, bx, cx)
	if [ay, by, cy].count(min_y) == 1:
		yy = min_y + 1
	else:
		yy = min_y
	if [ax, bx, cx].count(min_x) == 1:
		xx = min_x + 1
	else:
		xx = min_x
	if xx == yy == 0 and min_x == min_y == 0:
		print(0)
		return
	if xx == yy == 1 and min_x == min_y == 0:
		print(1)
		return
	if min_y < xx:
		x_same = max(abs(xx), abs(min_y)) * 2 - 1
	else:
		x_same = max(abs(xx), abs(min_y)) * 2
	if min_x < yy:
		y_same = max(abs(min_x), abs(yy)) * 2 - 1
	else:
		y_same = max(abs(min_x), abs(yy)) * 2
	ans = max(x_same, y_same)
	if x_same == y_same:
		ans += 1
	print(ans)
for _ in range(int(input())):
	main()


T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	if ax == bx:
		(x, xx) = (ax, cx)
	if bx == cx:
		(x, xx) = (bx, ax)
	if cx == ax:
		(x, xx) = (cx, bx)
	if ay == by:
		(y, yy) = (ay, cy)
	if by == cy:
		(y, yy) = (by, ay)
	if cy == ay:
		(y, yy) = (cy, by)
	(xx, yy) = (xx - x, yy - y)
	if x == y == 0:
		if xx == yy == 1:
			g = 0
		elif xx * yy == 1:
			g = 2
		else:
			g = 1
	elif x == 0:
		if y > 0:
			g = 2 * y - (yy == -1)
		else:
			g = -2 * y + (yy == -1)
	elif y == 0:
		if x > 0:
			g = 2 * x - (xx == -1)
		else:
			g = -2 * x + (xx == -1)
	elif x > 0 and y > 0:
		if x == y == 1:
			if xx == yy == -1:
				g = 1
			elif -1 in {xx, yy}:
				g = 2
			else:
				g = 3
		elif x == y:
			if -1 in {xx, yy}:
				g = 2 * max(x, y)
			else:
				g = 2 * max(x, y) + 1
		elif x > y:
			if xx == 1:
				g = 2 * x
			else:
				g = 2 * x - 1
		elif y > x:
			(x, y, xx, yy) = (y, x, yy, xx)
			if xx == 1:
				g = 2 * x
			else:
				g = 2 * x - 1
	elif x < 0 and y > 0:
		if x + y == 0:
			if xx == 1:
				g = 2 * y
			else:
				g = 2 * y + 1
		if x + y > 0:
			if yy == -1:
				g = 2 * y - 1
			else:
				g = 2 * y
		if x + y < 0:
			if xx == 1:
				g = -2 * x
			else:
				g = -2 * x + 1
	elif x > 0 and y < 0:
		(x, y, xx, yy) = (y, x, yy, xx)
		if x + y == 0:
			if xx == 1:
				g = 2 * y
			else:
				g = 2 * y + 1
		if x + y > 0:
			if yy == -1:
				g = 2 * y - 1
			else:
				g = 2 * y
		if x + y < 0:
			if xx == 1:
				g = -2 * x
			else:
				g = -2 * x + 1
	elif x == y:
		if xx == yy == -1:
			g = -2 * x + 2
		else:
			g = -2 * x + 1
	else:
		if x < y:
			if xx == 1:
				g = -2 * x
			else:
				g = -2 * x + 1
		if y < x:
			if yy == 1:
				g = -2 * y
			else:
				g = -2 * y + 1
	print(g)


T = int(input())

def solve(X, Y):
	if X > 0:
		x = X - int(X / 3)
	else:
		x = X + int((2 - X) / 3)
	x -= 1
	if Y > 0:
		y = Y - int(Y / 3)
	else:
		y = Y + int((2 - Y) / 3)
	y -= 1
	if x == 0 and y == 0:
		return 0
	if x == 1 and y == 1:
		return 1
	ans = max([x, -x, y, -y])
	if x == y:
		ans += 1
	return ans
for i in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	X = ax + bx + cx
	Y = ay + by + cy
	print(solve(X, Y))


cost = {}
tip = {}
d = {1: [(2, 1, 0), (3, 1, 0), (4, 0, 0), (3, 0, 1), (2, 0, 0), (4, 0, 1), (3, 1, 1)], 2: [(1, 0, 0), (3, 0, 1), (4, 0, 1), (1, -1, 0), (3, 0, 0), (4, -1, 0), (4, -1, 1)], 3: [(2, 0, 0), (1, -1, 0), (4, -1, 0), (4, 0, 0), (1, 0, -1), (2, 0, -1), (1, -1, -1)], 4: [(1, 0, -1), (2, 0, -1), (3, 0, 0), (1, 0, 0), (2, 1, 0), (3, 1, 0), (2, 1, -1)]}

def dfs(t, x, y, dist, cost):
	if dist >= 4:
		return []
	if (t, x, y) in cost:
		cost[t, x, y] = min(cost[t, x, y], dist)
	else:
		cost[t, x, y] = dist
	for e in d[t]:
		dfs(e[0], x + e[1], y + e[2], dist + 1, cost)
tip[(0, 1), (1, 0)] = 1
tip[(1, 0), (0, 1)] = 1
tip[(0, -1), (1, 0)] = 4
tip[(1, 0), (0, -1)] = 4
tip[(0, 1), (-1, 0)] = 2
tip[(-1, 0), (0, 1)] = 2
tip[(0, -1), (-1, 0)] = 3
tip[(-1, 0), (0, -1)] = 3

def test(a, b, c):
	if b[0] != c[0] and b[1] != c[1]:
		return True
	return False

def dd(a, b):
	return (b[0] - a[0], b[1] - a[1])

def conv(coords):
	a = (coords[0], coords[1])
	b = (coords[2], coords[3])
	c = (coords[4], coords[5])
	center = a
	o1 = b
	o2 = c
	if test(b, a, c):
		center = b
		o1 = a
		o2 = c
	if test(c, a, b):
		center = c
		o1 = a
		o2 = b
	tp = tip[dd(center, o1), dd(center, o2)]
	(x, y) = center
	return (tp, x, y)

def sgn(tp, dx, dy):
	if tp == 1 or tp == 3:
		if dx * dy <= 0:
			return 0
		return 1
	if dx * dy <= 0:
		return 1
	return 0

def get_cost(tp, x, y, xf, yf):
	diag = min(abs(x - xf), abs(y - yf))
	lin = max(abs(x - xf), abs(y - yf))
	return 2 * lin + sgn(tp, x - xf, y - yf) * 10

def solve(coords):
	(t, x, y) = conv(coords)
	to = {}
	dfs(t, x, y, 0, to)
	ans = 1e+18
	for e in cost:
		for f in to:
			if f[0] == e[0]:
				ans = min(ans, cost[e] + to[f] + get_cost(e[0], e[1], e[2], f[1], f[2]))
	return ans
lst = dfs(1, 0, 0, 0, cost)
n = int(input())
for i in range(n):
	coords = list(map(int, input().split()))
	print(solve(coords))


ansl = []
for q in range(int(input())):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	fs = [(0, 0), (0, 1), (1, 0)]
	fs2 = [(-1, 0), (0, 0), (0, -1)]
	if (ax, ay) in fs and (bx, by) in fs and ((cx, cy) in fs):
		ansl.append(0)
		continue
	if (ax, ay) in fs2 and (bx, by) in fs2 and ((cx, cy) in fs2):
		ansl.append(2)
		continue
	if (ax, ay) == (0, 0) or (bx, by) == (0, 0) or (cx, cy) == (0, 0):
		ans = 0
		if (ax, ay) not in fs:
			ans += 1
		if (bx, by) not in fs:
			ans += 1
		if (cx, cy) not in fs:
			ans += 1
		ansl.append(ans)
		continue
	if abs(ax) <= abs(ay) and abs(bx) <= abs(by) and (abs(cx) <= abs(cy)):
		(ax, ay) = (ay, ax)
		(bx, by) = (by, bx)
		(cx, cy) = (cy, cx)
	if abs(ax) >= abs(ay) and abs(bx) >= abs(by) and (abs(cx) >= abs(cy)):
		miny = min(ay, by, cy)
		ay -= miny
		by -= miny
		cy -= miny
		samex = 0
		if ax == bx:
			samex = ax
			difx = cx
		elif bx == cx:
			samex = bx
			difx = ax
		else:
			samex = cx
			difx = bx
		if difx < samex:
			dist = difx * 2 + 1
		else:
			dist = samex * 2
		dist = max(dist, dist * -1)
		ansl.append(dist)
	else:
		xp = 0
		if abs(ax) == abs(ay):
			xp = ax
			yp = ay
			if xp >= 0 and yp >= 0:
				if max(ay, by, cy) == yp:
					if ax == 1:
						dist = 1
					else:
						dist = abs(xp) * 2
				else:
					dist = abs(xp) * 2 + 1
			elif xp < 0 and yp < 0:
				if max(ay, by, cy) == yp:
					dist = abs(xp) * 2 + 2
				else:
					dist = abs(xp) * 2 + 1
			elif xp >= 0 and yp < 0:
				if max(ay, by, cy) == yp:
					dist = abs(xp) * 2 + 1
				else:
					dist = abs(xp) * 2
			elif max(ay, by, cy) == yp:
				dist = abs(xp) * 2
			else:
				dist = abs(xp) * 2 + 1
		elif abs(bx) == abs(by):
			xp = bx
			yp = by
			if xp >= 0 and yp >= 0:
				if max(ay, by, cy) == yp:
					if bx == 1:
						dist = 1
					else:
						dist = abs(xp) * 2
				else:
					dist = abs(xp) * 2 + 1
			elif xp < 0 and yp < 0:
				if max(ay, by, cy) == yp:
					dist = abs(xp) * 2 + 2
				else:
					dist = abs(xp) * 2 + 1
			elif xp >= 0 and yp < 0:
				if max(ay, by, cy) == yp:
					dist = abs(xp) * 2 + 1
				else:
					dist = abs(xp) * 2
			elif max(ay, by, cy) == yp:
				dist = abs(xp) * 2
			else:
				dist = abs(xp) * 2 + 1
		elif abs(cx) == abs(cy):
			xp = cx
			yp = cy
			if xp >= 0 and yp >= 0:
				if max(ay, by, cy) == yp:
					if cx == 1:
						dist = 1
					else:
						dist = abs(xp) * 2
				else:
					dist = abs(xp) * 2 + 1
			elif xp < 0 and yp < 0:
				if max(ay, by, cy) == yp:
					dist = abs(xp) * 2 + 2
				else:
					dist = abs(xp) * 2 + 1
			elif xp >= 0 and yp < 0:
				if max(ay, by, cy) == yp:
					dist = abs(xp) * 2 + 1
				else:
					dist = abs(xp) * 2
			elif max(ay, by, cy) == yp:
				dist = abs(xp) * 2
			else:
				dist = abs(xp) * 2 + 1
		ansl.append(dist)
for a in ansl:
	print(a)


from math import ceil, floor

def angle(a, b, c, d, e, f):
	res = []
	if a != c and b != d:
		center = (e, f)
		p = (a, b)
		q = (c, d)
	elif a != e and b != f:
		center = (c, d)
		p = (a, b)
		q = (e, f)
	else:
		center = (a, b)
		p = (c, d)
		q = (e, f)
	if center[0] == p[0]:
		if center[0] > q[0]:
			res.append('r')
		else:
			res.append('l')
	elif center[0] == q[0]:
		if center[0] > p[0]:
			res.append('r')
		else:
			res.append('l')
	if center[1] == p[1]:
		if center[1] < q[1]:
			res.append('d')
		else:
			res.append('u')
	elif center[1] == q[1]:
		if center[1] < p[1]:
			res.append('d')
		else:
			res.append('u')
	return res

def test():
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	if set([(ax, ay), (bx, by), (cx, cy)]) == set([(0, 0), (0, 1), (1, 0)]):
		return 0
	XX = (ax + bx + cx) / 3
	YY = (ay + by + cy) / 3
	ang = angle(ax, ay, bx, by, cx, cy)
	if XX > 0 and YY > 0:
		x = ceil(XX)
		y = ceil(YY)
		if (x, y) == (1, 1):
			return 1
		if x == y:
			tmp = x * 2 - 1
			if 'r' in ang and 'u' in ang:
				return tmp + 1
			return tmp
		tmp = (max(x, y) - 1) * 2
		if x > y and 'r' in ang:
			return tmp + 1
		elif y > x and 'u' in ang:
			return tmp + 1
		return tmp
	elif XX < 0 and YY > 0:
		x = floor(XX)
		y = ceil(YY)
		x = abs(x)
		if x >= y:
			tmp = x * 2 - 1
			if 'l' in ang:
				return tmp + 1
			return tmp
		else:
			tmp = (y - 1) * 2
			if 'u' in ang:
				return tmp + 1
			return tmp
	elif XX > 0 and YY < 0:
		x = ceil(XX)
		y = floor(YY)
		y = abs(y)
		if y >= x:
			tmp = y * 2 - 1
			if 'd' in ang:
				return tmp + 1
			return tmp
		else:
			tmp = (x - 1) * 2
			if 'r' in ang:
				return tmp + 1
			return tmp
	else:
		x = floor(XX)
		y = floor(YY)
		x = abs(x)
		y = abs(y)
		if x == y:
			tmp = 2 * x
			if 'd' in ang and 'l' in ang:
				return tmp + 1
			return tmp
		tmp = max(x, y) * 2 - 1
		if x > y and 'l' in ang:
			return tmp + 1
		if y > x and 'd' in ang:
			return tmp + 1
		return tmp
t = int(input())
for _ in range(t):
	print(test())


exec('a,b,c,d,e,f=map(int,input().split());g=a+c+e-max([a,c,e]);h=b+d+f-max([b,d,f]);print(max([abs(g),abs(h)])+(g*~-g and g==h));' * int(input()))


from queue import deque

def move(ku):
	(x, y, dx, dy) = ku
	return ((x + dx, y + dy, -dx, -dy), (x, y, -dx, dy), (x, y + dy, -dx, -dy), (x, y + dy, dx, -dy), (x, y, dx, -dy), (x + dx, y, -dx, dy), (x + dx, y, -dx, -dy))

def calc(x, y, dx, dy):
	if dx == 1 and dy == 1:
		if x == 0 and y == 0:
			return 0
		elif x == y:
			return abs(x) * 2 + 1
		else:
			return max(abs(x), abs(y)) * 2
	elif dx == -1 and dy == 1:
		if x == 0 and y == 0:
			return 1
		elif abs(x) - abs(y) == 0:
			if x < 0:
				return abs(x) * 2 + 1
			else:
				return abs(y) * 2
		elif abs(x) - abs(y) < 0:
			return abs(y) * 2
		elif x < 0:
			return abs(x) * 2 + 1
		else:
			return abs(x) * 2 - 1
	elif dx == 1 and dy == -1:
		if y <= 0:
			if abs(x) - abs(y) <= 0:
				return abs(y) * 2 + 1
			else:
				return abs(x) * 2
		elif abs(x) - abs(y) < 0:
			return abs(y) * 2 - 1
		else:
			return abs(x) * 2
	elif x == 0 and y == 0:
		return 2
	elif x == 1 and y == 1:
		return 1
	elif y < 0:
		if x < 0:
			if abs(x) - abs(y) == 0:
				return abs(x) * 2 + 2
			elif abs(x) - abs(y) < 0:
				return abs(y) * 2 + 1
			else:
				return abs(x) * 2 + 1
		elif abs(x) - abs(y) == 0:
			return abs(x) * 2 + 1
		elif abs(x) - abs(y) < 0:
			return abs(y) * 2 + 1
		else:
			return abs(x) * 2 - 1
	elif x < 0:
		if abs(x) - abs(y) < -1:
			return abs(y) * 2 - 1
		else:
			return abs(x) * 2 + 1
	elif abs(x) - abs(y) == 0:
		return abs(x) * 2
	elif abs(x) - abs(y) < 0:
		return abs(y) * 2 - 1
	else:
		return abs(x) * 2 - 1
T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	if ax == bx:
		gx = ax
	elif bx == cx:
		gx = bx
	else:
		gx = cx
	if ay == by:
		gy = ay
	elif by == cy:
		gy = by
	else:
		gy = cy
	xs = [ax, bx, cx]
	xs.remove(gx)
	xs.remove(gx)
	ys = [ay, by, cy]
	ys.remove(gy)
	ys.remove(gy)
	dx = xs[0] - gx
	dy = ys[0] - gy
	print(calc(gx, gy, dx, dy))


t = int(input())
for _ in range(t):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	mnx = min(ax, bx, cx)
	mny = min(ay, by, cy)
	tp = ((ax, ay), (bx, by), (cx, cy))
	ans = 0
	if (mnx + 1, mny + 1) not in tp:
		if mnx == mny and mnx != 0:
			ans += 1
		ans += max(abs(mnx), abs(mny)) * 2
		print(ans)
	elif (mnx + 1, mny) not in tp:
		mnx = abs(mnx)
		if mny < 0:
			mny = abs(mny + 1)
		if mnx > mny:
			print(mnx * 2)
		else:
			print(mny * 2 + 1)
	elif (mnx, mny + 1) not in tp:
		mny = abs(mny)
		if mnx < 0:
			mnx = abs(mnx + 1)
		if mny > mnx:
			print(mny * 2)
		else:
			print(mnx * 2 + 1)
	else:
		ans += 1
		if mnx == mny and mnx != 0:
			ans += 1
		if mnx < 0:
			mnx = abs(mnx + 1)
		if mny < 0:
			mny = abs(mny + 1)
		ans += max(abs(mnx), abs(mny)) * 2
		print(ans)


def func(ary):
	a = ary[0:2]
	b = ary[2:4]
	c = ary[4:6]
	x = a[0] + b[0] + c[0]
	y = a[1] + b[1] + c[1]
	if x > 0:
		x -= x // 3
	else:
		x += 1 + abs(x) // 3
	if y > 0:
		y -= y // 3
	else:
		y += 1 + abs(y) // 3
	if x != y:
		t = max(abs(x - 1), abs(y - 1))
		return t
	elif x > 0:
		x -= 1
		if x == 0:
			return 0
		if x == 1:
			return 1
		return x + 1
	else:
		return abs(x - 1) + 1
t = int(input())
query = [list(map(int, input().split())) for _ in range(t)]
for x in query:
	print(func(x))


import numpy as np
import sys
from sys import stdin

def short(v):
	x = (v[0] + v[2] + v[4]) // 3 * 2 + (v[0] + v[2] + v[4]) % 3 - 1
	y = (v[1] + v[3] + v[5]) // 3 * 2 + (v[1] + v[3] + v[5]) % 3 - 1
	s = 0
	M = max(abs(x), abs(y))
	s = s + M
	if x == y and x * (x - 1) != 0:
		s = s + 1
	print(s)
	return

def main():
	for i in range(t):
		short(c[i])
	return
input = sys.stdin.readline
t = int(input())
c = [list(map(int, input().split())) for _ in range(t)]
main()


t = int(input())
for i in range(t):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	x = min(ax, bx, cx)
	y = min(ay, by, cy)
	ans = 0
	if x >= 0 and y >= 0:
		if x == 0 and y == 0:
			pass
		else:
			ans += 1
	num = abs(abs(x) - abs(y))
	if x >= 0:
		if y >= 0:
			ans += max(num - 1, 0)
		elif abs(x) > abs(y):
			ans += num
		else:
			ans += max(num - 1, 0)
	elif y >= 0:
		if abs(y) > abs(x):
			ans += num
		else:
			ans += max(num - 1, 0)
	else:
		ans += max(num - 1, 0)
	ans += abs(x) + abs(y)
	if x >= 0:
		if y >= 0:
			if round((ax + bx + cx) / 3) == max(ax, bx, cx) and round((ay + by + cy) / 3) == max(ay, by, cy):
				ans += 1
			elif abs(x) > abs(y):
				if round((ax + bx + cx) / 3) == max(ax, bx, cx):
					ans += 1
			elif abs(y) > abs(x):
				if round((ay + by + cy) / 3) == max(ay, by, cy):
					ans += 1
			elif x == 0 and y == 0:
				if round((ax + bx + cx) / 3) == max(ax, bx, cx) or round((ay + by + cy) / 3) == max(ay, by, cy):
					ans += 1
		elif round((ax + bx + cx) / 3) == max(ax, bx, cx) and round((ay + by + cy) / 3) == min(ay, by, cy):
			ans += 1
		elif abs(x) >= abs(y):
			if round((ax + bx + cx) / 3) == max(ax, bx, cx):
				ans += 1
		elif abs(y) > abs(x):
			if round((ay + by + cy) / 3) == min(ay, by, cy):
				ans += 1
	elif y >= 0:
		if round((ax + bx + cx) / 3) == min(ax, bx, cx) and round((ay + by + cy) / 3) == max(ay, by, cy):
			ans += 1
		elif abs(x) > abs(y):
			if round((ax + bx + cx) / 3) == min(ax, bx, cx):
				ans += 1
		elif abs(y) >= abs(x):
			if round((ay + by + cy) / 3) == max(ay, by, cy):
				ans += 1
	elif round((ax + bx + cx) / 3) == min(ax, bx, cx) and round((ay + by + cy) / 3) == min(ay, by, cy):
		ans += 1
	elif abs(x) > abs(y):
		if round((ax + bx + cx) / 3) == min(ax, bx, cx):
			ans += 1
	elif abs(y) > abs(x):
		if round((ay + by + cy) / 3) == min(ay, by, cy):
			ans += 1
	print(ans)


T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	mx = min(ax, bx, cx)
	dx = (ax + bx + cx) % 3 - 1
	x = 2 * mx + dx
	my = min(ay, by, cy)
	dy = (ay + by + cy) % 3 - 1
	y = 2 * my + dy
	print(max(abs(x), abs(y)) + (1 if x == y and (mx != 0 or my != 0) else 0))


from collections import deque
inpl = lambda : list(map(int, input().split()))

def sign(x):
	return (x > 0) - (x < 0)
trans = {(1, 0, 0), (1, 1, 0), (2, 1, 0), (2, 0, 1), (2, 1, 1), (3, 0, 0), (3, 0, 1)}
all_trans = [trans]
for i in range(3):
	w = set()
	for (s, x, y) in all_trans[-1]:
		ns = (s + 1) % 4
		nx = -y
		ny = x
		w.add((ns, nx, ny))
	all_trans.append(w)
V = {(1, 1): 0, (-1, 1): 1, (-1, -1): 2, (1, -1): 3}
que = deque([(0, 0, 0, 0)])
bfs = dict()
bfs[0, 0, 0] = 0
while que:
	(s, x, y, d) = que.popleft()
	if d > 10:
		break
	for (ns, dx, dy) in all_trans[s]:
		nx = x + dx
		ny = y + dy
		if not (ns, nx, ny) in bfs:
			que.append((ns, nx, ny, d + 1))
			bfs[ns, nx, ny] = d + 1
T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = inpl()
	if ax == bx:
		(px, qx) = (ax, cx)
	elif ax == cx:
		(px, qx) = (ax, bx)
	else:
		(px, qx) = (bx, ax)
	if ay == by:
		(py, qy) = (ay, cy)
	elif ay == cy:
		(py, qy) = (ay, by)
	else:
		(py, qy) = (by, ay)
	ps = V[qx - px, qy - py]
	ans = 0
	(th1, th2) = (3, 3)
	if abs(px) + abs(py) > th1:
		k = min(abs(px), abs(py))
		l = abs(abs(px) - abs(py))
		if l < th1:
			k -= (th1 - l + 1) // 2
		px -= sign(px) * k
		py -= sign(py) * k
		ans += k * 2
		if abs(px) > th2:
			m = abs(px) - th2
			px -= sign(px) * m
			ans += m * 2
		elif abs(py) > th2:
			m = abs(py) - th2
			py -= sign(py) * m
			ans += m * 2
	ans += bfs[ps, px, py]
	print(ans)


(N, *PQRSTU) = [int(_) for _ in open(0).read().split()]
(P, Q, R, S, T, U) = [PQRSTU[_::len('PQRSTU')] for _ in range(len('PQRSTU'))]

def calc(x1, y1, x2, y2, x3, y3):
	gx = x1 + x2 + x3
	gy = y1 + y2 + y3
	if gx > gy:
		(gx, gy) = (gy, gx)
	(x, dx) = divmod(gx, 3)
	(y, dy) = divmod(gy, 3)
	if x == y:
		if x == 0:
			ret = 1 - (dx * dy == 1)
		elif x > 0:
			ret = 2 * y + 1 + (dx == dy == 2)
		else:
			ret = -2 * y + (dx * dy == 1)
	elif x + abs(y) < 0:
		ret = -2 * x - (dx == 2)
	else:
		ret = 2 * y + (dy == 2)
	return ret
ans = []
for (p, q, r, s, t, u) in zip(P, Q, R, S, T, U):
	ans += [calc(p, q, r, s, t, u)]
print('\n'.join(map(str, ans)))


T = int(input())
for t in range(T):
	(ax, ay, bx, by, cx, cy) = [int(i) for i in input().split()]
	([ax, ay], [bx, by], [cx, cy]) = sorted([[ax, ay], [bx, by], [cx, cy]], key=lambda x: x[1])
	([ax, ay], [bx, by], [cx, cy]) = sorted([[ax, ay], [bx, by], [cx, cy]], key=lambda x: x[0])
	if [ax, ay, bx, by, cx, cy] == [0, 0, 0, 1, 1, 0]:
		print(0)
		continue
	elif [ax, ay, bx, by, cx, cy] == [0, 1, 1, 0, 1, 1]:
		print(1)
		continue
	if [bx, by - 1] == [ax, ay] and [cx - 1, cy] == [ax, ay]:
		g = [bx + cx - 1, by + cy - 1]
	if [bx, by - 1] == [ax, ay] and [cx - 1, cy - 1] == [ax, ay]:
		g = [ax + cx - 1, ay + cy]
	if [bx - 1, by + 1] == [ax, ay] and [cx - 1, cy] == [ax, ay]:
		g = [ax + bx, ay + by]
	if [bx - 1, by] == [ax, ay] and [cx - 1, cy - 1] == [ax, ay]:
		g = [ax + cx, ay + cy - 1]
	ans = max([abs(x) for x in g]) + (g[0] == g[1])
	print(ans)


T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	xdis = ax + bx + cx - 1
	ydis = ay + by + cy - 1
	if xdis % 3 == 0:
		xneed = abs(xdis) * 2 // 3
	if xdis % 3 == 1:
		xneed = (abs(xdis) * 2 + 1) // 3
	if xdis % 3 == 2:
		xneed = (abs(xdis) * 2 + 2) // 3
	if ydis % 3 == 0:
		yneed = abs(ydis) * 2 // 3
	if ydis % 3 == 1:
		yneed = (abs(ydis) * 2 + 1) // 3
	if ydis % 3 == 2:
		yneed = (abs(ydis) * 2 + 2) // 3
	if xdis * ydis > 1 and xneed == yneed:
		print(xneed + 1)
	else:
		print(max(xneed, yneed))


def solve(T, case):

	def solver(X, Y):
		X = (X - X // 3 if X > 0 else X + (2 - X) // 3) - 1
		Y = (Y - Y // 3 if Y > 0 else Y + (2 - Y) // 3) - 1
		if X == Y == 0:
			return 0
		if X == Y == 1:
			return 1
		return max(X, -X, Y, -Y) + (X == Y)
	for (ax, ay, bx, by, cx, cy) in case:
		print(solver(ax + bx + cx, ay + by + cy))

def __starting_point():
	T = int(input())
	case = [[int(i) for i in input().split()] for _ in range(T)]
	solve(T, case)
__starting_point()


t = int(input())
buf = []
for _ in range(t):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	mx = min(ax, bx, cx)
	my = min(ay, by, cy)
	dx = (ax == mx) + (bx == mx) + (cx == mx)
	dy = (ay == my) + (by == my) + (cy == my)
	if mx == 0 and my == 0:
		if dx == 2 and dy == 2:
			buf.append(0)
		else:
			buf.append(1)
		continue
	(rx, ry) = (False, False)
	if mx < 0:
		mx = -mx
		dx = 3 - dx
		rx = True
	if my < 0:
		my = -my
		dy = 3 - dy
		ry = True
	ans = 2 * max(mx, my)
	if mx == my:
		ans += 1
		if rx or ry:
			ans -= 1
			if rx == False and dx == 1 or (ry == False and dy == 1):
				ans += 1
			elif rx and ry and (dx == 1) and (dy == 1):
				ans += 1
		elif dx == 1 and dy == 1:
			ans += 1
	elif mx > my:
		if rx:
			ans -= 1
		if dx == 1:
			ans += 1
	elif mx < my:
		if ry:
			ans -= 1
		if dy == 1:
			ans += 1
	buf.append(ans)
print('\n'.join(map(str, buf)))


def scorec(x, y):
	if x == y and x > 0:
		score = 2 * x - 1
	elif x == y and x < 0:
		score = 2 * abs(x)
	elif y + x > 0:
		score = 2 * max(abs(x), abs(y)) - 2
	else:
		score = 2 * max(abs(x), abs(y)) - 1
	return max(0, score)
t = int(input())
for _ in range(t):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	overlap = 0
	ans1 = scorec(ax, ay)
	if ans1 <= 0:
		overlap += 1
	ans2 = scorec(bx, by)
	if ans2 <= 0:
		overlap += 1
	ans3 = scorec(cx, cy)
	if ans3 <= 0:
		overlap += 1
	ans = min(ans1, ans2, ans3)
	if overlap >= 2:
		print(3 - overlap)
		continue
	if ans + 2 == ans1 and ans + 2 == ans2 or (ans + 2 == ans2 and ans + 2 == ans3) or (ans + 2 == ans1 and ans + 2 == ans3):
		ans += 1
	print(ans + 2)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10 ** 9))
write = lambda x: sys.stdout.write(x + '\n')
_turnx = {1: 4, 2: 3, 3: 2, 4: 1}
_turn90 = {1: 4, 2: 3, 3: 1, 4: 2}

def subx(a, b, d):
	if isinstance(a, tuple):
		return min((subx(item, b, d) for item in a))
	if d < 0:
		return subx(_turnx[a], _turnx[b], -d)
	return suby(_turn90[a], _turn90[b], d)
_turny = {1: 3, 2: 4, 3: 1, 4: 2}

def suby(a, b, d):
	if isinstance(a, tuple):
		return min((suby(item, b, d) for item in a))
	if d < 0:
		return suby(_turny[a], _turny[b], -d)
	elif d == 0:
		if a == b:
			return 0
		else:
			return 1
	elif d == 1:
		if a in (2, 3) and b in (1, 4):
			return 1
		elif a in (1, 4) and b in (2, 3):
			return 3
		else:
			return 2
	else:
		ans = 2 * (d - 2)
		if a in (1, 4):
			ans += 3
		else:
			ans += 2
		if b in (1, 4):
			ans += 1
		else:
			ans += 2
	return ans
ans = float('inf')
t = int(input())
for ind in range(t):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	if ax != bx:
		if bx == cx:
			(ax, ay, cx, cy) = (cx, cy, ax, ay)
		else:
			(bx, by, cx, cy) = (cx, cy, bx, by)
	if cx > ax:
		if cy == max(ay, by):
			k = 3
		else:
			k = 1
	elif cy == max(ay, by):
		k = 2
	else:
		k = 4
	(tx, ty) = (min(ax, bx, cx), min(ay, by, cy))
	if tx == 0:
		if ty == 0:
			ans = suby(1, k, 0)
		else:
			ans = suby(1, k, ty)
	elif ty == 0:
		ans = subx(1, k, tx)
	elif tx > 0 and ty > 0:
		ans = 2 * min(tx, ty) + 1
		if tx > ty:
			ans += subx((1, 3, 4), k, tx - ty)
		elif ty > tx:
			ans += suby((1, 3, 4), k, ty - tx)
		else:
			ans += suby((1, 3, 4), k, 0)
	elif tx > 0 and ty < 0:
		(tx, ty) = (abs(tx), abs(ty))
		ans = 2 * min(tx, ty)
		if tx > ty:
			ans += subx((1, 3), k, tx - ty)
		elif ty > tx:
			ans += suby((1, 3), k, tx - ty)
		else:
			ans += suby((1, 3), k, 0)
	elif tx < 0 and ty > 0:
		(tx, ty) = (abs(tx), abs(ty))
		ans = 2 * min(tx, ty)
		if tx > ty:
			ans += subx((1, 4), k, -tx + ty)
		elif ty > tx:
			ans += suby((1, 4), k, -tx + ty)
		else:
			ans += suby((1, 4), k, 0)
	else:
		(tx, ty) = (abs(tx), abs(ty))
		ans = 2 * min(tx, ty)
		if tx > ty:
			ans += subx((2, 3, 4), k, ty - tx)
		elif ty > tx:
			ans += suby((2, 3, 4), k, tx - ty)
		else:
			ans += suby((2, 3, 4), k, 0)
	print(ans)


X = [[(0, 0, 1), (1, 0, 1), (0, 1, 2), (1, 0, 2), (1, 1, 2), (0, 0, 3), (0, 1, 3)], [(0, 0, 2), (0, 1, 2), (-1, 0, 3), (0, 1, 3), (-1, 1, 3), (0, 0, 0), (-1, 0, 0)], [(0, 0, 3), (-1, 0, 3), (0, -1, 0), (-1, 0, 0), (-1, -1, 0), (0, 0, 1), (0, -1, 1)], [(0, 0, 0), (0, -1, 0), (1, 0, 1), (0, -1, 1), (1, -1, 1), (0, 0, 2), (1, 0, 2)]]
A = [[(0, 0, 0)], [(0, 0, 1), (1, 0, 1), (0, 1, 2), (1, 0, 2), (1, 1, 2), (0, 0, 3), (0, 1, 3)], [(0, 0, 2), (-1, 0, 3), (-1, 1, 3), (-1, 0, 0), (1, 1, 3), (1, 0, 0), (-1, 1, 3), (-1, 1, 0), (-1, 0, 0), (0, 1, 1), (1, 0, 3), (1, -1, 0), (0, -1, 0), (1, -1, 1), (1, 1, 3), (1, 0, 0), (0, 1, 0), (1, 1, 1), (0, -1, 0), (0, -1, 1), (1, -1, 1), (0, 0, 2), (0, 1, 0), (1, 1, 1)]]
T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = map(int, input().split())
	sx = ax + bx + cx
	sy = ay + by + cy
	(sx3, sy3) = (sx % 3, sy % 3)
	tp = [0, 3, 1, 2][(sx3 - 1) * 2 + (sy3 - 1)]
	(x, y) = ((sx + 1) // 3, (sy + 1) // 3)
	(x0, y0, tp0) = (0, 0, 0)
	if (x, y, tp) == (x0, y0, tp0):
		print(0)
		continue
	if (x, y, tp) in X[tp0]:
		print(1)
		continue
	B = [[(x, y, tp)], [], []]
	for i in range(2):
		for (x, y, tp) in B[i]:
			for (dx, dy, ntp) in X[tp]:
				B[i + 1].append((x + dx, y + dy, ntp))
	mi = 10 ** 30
	for i in range(3):
		for (x1, y1, t1) in A[i]:
			for j in range(3):
				for (x2, y2, t2) in B[j]:
					if t1 == t2:
						d = max(abs(x1 - x2), abs(y1 - y2)) * 2 + i + j
						p = (x1 - x2) * (y1 - y2)
						if p >= 0 and t1 % 2 or (p <= 0 and t1 % 2 == 0):
							if d < mi:
								mi = d
	print(mi)


def dp1(x, y):
	if x == 0 and y == 0:
		return 0
	if x == y:
		return 2 * x - 1
	else:
		return (max(x, y) - 1) * 2

def dp2(x, y):
	if x >= y:
		return 2 * x - 1
	else:
		return 2 * y - 2

def dp3(x, y):
	if x == y:
		return 2 * x
	else:
		return 2 * max(x, y) - 1

def dp(x, y):
	if x >= 0 and y >= 0:
		return dp1(x, y)
	if x < 0 and y < 0:
		return dp3(-x, -y)
	if x < 0:
		return dp2(-x, y)
	return dp2(-y, x)

def solve(ax, ay, bx, by, cx, cy):
	a = dp(ax, ay)
	b = dp(bx, by)
	c = dp(cx, cy)
	d = max(a, b, c)
	if d == 0:
		return 0
	count = 0
	if a == d:
		count += 1
	if b == d:
		count += 1
	if c == d:
		count += 1
	if count == 1:
		if a + b + c == 3 * d - 2 and d > 1:
			return d + 1
		else:
			return d
	else:
		return d + 1

def main(in_file):
	f = open(in_file)
	t = int(f.readline())
	for _ in range(t):
		(ax, ay, bx, by, cx, cy) = [int(x) for x in f.readline().split()]
		print(solve(ax, ay, bx, by, cx, cy))

def __starting_point():
	main(0)
__starting_point()


T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	x = ax + bx + cx
	y = ay + by + cy
	if x == y:
		if x == 1:
			print(0)
		elif x == 2:
			print(1)
		elif x > 0:
			if x % 3 == 2:
				print((x + 1) // 3 * 2)
			else:
				print((x - 1) // 3 * 2 + 1)
		else:
			x = -x
			if x % 3 == 2:
				print((x + 1) // 3 * 2 + 1)
			else:
				print((x + 2) // 3 * 2)
	else:
		res = 0
		for d in (x, y):
			if d % 3 == 2:
				if d > 0:
					res = max(res, (d - 2) // 3 * 2 + 1)
				else:
					res = max(res, (-d - 1) // 3 * 2 + 1)
			elif d > 0:
				res = max(res, (d - 1) // 3 * 2)
			else:
				res = max(res, (-d + 1) // 3 * 2)
		print(res)


import sys
from math import floor

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

def sub(ax, ay, bx, by, cx, cy):
	(mx, my) = ((ax + bx + cx) / 3, (ay + by + cy) / 3)
	(mx, my) = (floor(mx * 2), floor(my * 2))
	k = max(abs(mx), abs(my))
	if k == 0:
		return 0
	if k <= 1:
		return 1 if (mx, my) != (-1, -1) else 2
	return k if mx != my else k + 1

def main():
	T = int(input())
	ans_list = []
	for _ in range(T):
		(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
		ans_list.append(sub(ax, ay, bx, by, cx, cy))
	for ans in ans_list:
		print(ans)

def __starting_point():
	main()
__starting_point()


T = int(input())
A = []

def direction(inp):
	if inp.count(min(inp)) == 1:
		return 1
	else:
		return 0
for i in range(T):
	(x1, y1, x2, y2, x3, y3) = map(int, input().split())
	x = [x1, x2, x3]
	y = [y1, y2, y3]
	dst = [min(x) * 2 + direction(x), min(y) * 2 + direction(y)]
	step = max(abs(dst[0]), abs(dst[1]))
	if dst == [0, 0]:
		step = 0
	elif dst == [1, 1]:
		step = 1
	elif dst[0] == dst[1]:
		step += 1
	A += [step]
for i in A:
	print(str(i))


import math
import collections
for z in range(int(input())):
	a = [tuple for i in range(3)]
	A = list(map(int, input().strip().split()))
	(X, Y) = (0, 0)
	j = 0
	for i in range(3):
		(x, y) = (A[2 * i], A[2 * i + 1])
		X += x
		Y += y
		j += 1
	Z = -X
	if X > 0:
		X -= X // 3
	else:
		X += (2 - X) // 3
	Z = -Y
	if Y > 0:
		Y -= Y // 3
	else:
		Y += (2 - Y) // 3
	if X == 1 and Y == 1:
		print(0)
	elif X == 2 and Y == 2:
		print(1)
	elif X == Y:
		print(max(abs(X - 1), abs(Y - 1)) + 1)
	else:
		print(max(abs(X - 1), abs(Y - 1)))


T = int(input())
for _ in range(T):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	ldx = min(ax, bx, cx)
	ldy = min(ay, by, cy)
	isleft = int((ax, bx, cx).count(ldx) == 2)
	if ldx > 0:
		transx = ldx + (1 - isleft)
	elif ldx < 0:
		transx = abs(ldx) + isleft - 1
	else:
		transx = 1 - isleft
	isdown = int((ay, by, cy).count(ldy) == 2)
	if ldy > 0:
		transy = ldy + (1 - isdown)
	elif ldy < 0:
		transy = abs(ldy) + isdown - 1
	else:
		transy = 1 - isdown
	ans = 0
	if ldx == ldy != 0 and isdown == isleft:
		ans += 1
	ans += max(transy + abs(ldy), transx + abs(ldx))
	print(ans)


def solve2(p):
	P = (sum(p[0::2]), sum(p[1::2]))
	x = P[0] // 3 * 2 + (P[0] - 1) % 3
	y = P[1] // 3 * 2 + (P[1] - 1) % 3
	if x == y:
		if x == 0:
			print(0)
			return '0'
		elif x == 1:
			print(1)
			return '1'
		elif x > 0:
			print(x + 1)
			return str(x + 1)
		else:
			print(-x + 1)
			return str(1 - x)
	else:
		print(max(abs(x), abs(y)))
		return str(max(abs(x), abs(y)))

def main():
	N = int(input())
	Ps = [list(map(int, input().split())) for _ in range(N)]
	for P in Ps:
		solve2(P)

def __starting_point():
	main()
__starting_point()


for _ in range(int(input())):
	(ax, ay, bx, by, cx, cy) = list(map(int, input().split()))
	x = min(ax, bx, cx)
	y = min(ay, by, cy)
	if [x, y] not in [[ax, ay], [bx, by], [cx, cy]]:
		x = 2 * x + 1
		y = 2 * y + 1
	elif [x + 1, y] not in [[ax, ay], [bx, by], [cx, cy]]:
		x *= 2
		y = 2 * y + 1
	elif [x, y + 1] not in [[ax, ay], [bx, by], [cx, cy]]:
		x = 2 * x + 1
		y *= 2
	else:
		x *= 2
		y *= 2
	if x != y:
		print(max(abs(x), abs(y)))
	elif x == 0 or x == 1:
		print(x)
	else:
		print(abs(x) + 1)


def count(x, y, p, q):
	res = 0
	if x == 0 and y == 0:
		if p == -1 and q == -1:
			return 0
		else:
			return 1
	if x == 0 or y == 0:
		if y == 0:
			(x, y) = (y, x)
			(p, q) = (q, p)
		if y > 0:
			res += 2 * y
			if q == +1:
				res += 1
		if y < 0:
			res += -2 * y - 1
			if q == -1:
				res += 1
		return res
	(p0, q0) = (-1, -1)
	if x < 0:
		x = -x
		p = -p
		p0 = -p0
	if y < 0:
		y = -y
		q = -q
		q0 = -q0
	if x > y:
		(x, y) = (y, x)
		(p, q) = (q, p)
		(p0, q0) = (q0, p0)
	res += 2 * x
	if x == y:
		if p0 * q0 == -1 and p * q == -1:
			if p0 != p or q0 != q:
				res += 1
		if p0 + q0 == -2:
			res += 1
		if p + q == 2:
			res += 1
		return res
	if p0 + q0 == -2:
		res += 1
	if p0 == 1 and q0 == -1:
		res += 1
	res += 2 * (y - x) - 1
	if q == +1:
		res += 1
	return res
T = int(input())
xy = [list(map(int, input().split())) for _ in range(T)]
for t in range(T):
	(ax, ay, bx, by, cx, cy) = xy[t]
	x = sum(list(set([ax, bx, cx])))
	y = sum(list(set([ay, by, cy])))
	if (ax + bx + cx) / 3 - x / 2 > 0:
		p = 1
	else:
		p = -1
	if (ay + by + cy) / 3 - y / 2 > 0:
		q = 1
	else:
		q = -1
	ans = count((x - 1) // 2, (y - 1) // 2, p, q)
	print(ans)