chess-lovers

Programmers generally love to play chess! You too have recently acquired an interest in playing chess and you find bishop to be the most fascinating warrior of all. During a random chess practice session, you are faced with this problem : 

"Two bishops are lying on the chessboard. You can move only one of them. What is the minimum number of moves required to put the two bishops in an attacking position? "

Here, a move is equivalent to moving the bishop diagonally on the chess board. If the answer is greater than or equal to 10^15, output -1.

Input Format

First line contains T , the number of test cases. Each of the next "T" lines contains X1 Y1 X2 Y2, denoting the positions of the two bishops on the chessboard.

Output Format

For each of the T test cases, output the answer as required.

Constraints

**1 ≤ T ≤ 10^5

1 ≤ X1 , X2 , Y1 , Y2 ≤ 8**

SAMPLE INPUT
2
1 1 1 2
2 2 3 3

SAMPLE OUTPUT
-1
0

Source: hackerearth | Difficulty: EASY


Solutions:
def diagonal(x1, y1, x2, y2):
	if abs(x1 - x2) == abs(y1 - y2):
		return True
	return False


def solve():
	C = [
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 1, 0, 1, 0, 1, 0, 1],
		[0, 1, 0, 1, 0, 1, 0, 1, 0],
		[0, 0, 1, 0, 1, 0, 1, 0, 1],
		[0, 1, 0, 1, 0, 1, 0, 1, 0],
		[0, 0, 1, 0, 1, 0, 1, 0, 1],
		[0, 1, 0, 1, 0, 1, 0, 1, 0],
		[0, 0, 1, 0, 1, 0, 1, 0, 1],
		[0, 1, 0, 1, 0, 1, 0, 1, 0],
	]
	for _ in range(eval(input())):
		x1, y1, x2, y2 = list(map(int, input().split()))

		if any(x > 8 or x < 1 for x in [x1, x2, y1, y2]):
			print(-1)
			continue

		if diagonal(x1, y1, x2, y2):
			print(0)

		elif C[x1][y1] != C[x2][y2]:
			print(-1)
		else:
			print(1)


if __name__ == '__main__':
	limit = 10 ** 15
	solve()


def moveDiagonally(x1, y1, x2,  y2):
	i, j = x1 + 1, y1 + 1
	while i < 9 and j < 9:
		if diagonal(i, j, x2, y2):
			return True
		i, j = i + 1, j + 1

	i, j = x1 - 1, y1 - 1
	while i > 0 and j > 0:
		if diagonal(i, j, x2, y2):
			return True
		i, j = i - 1, j - 1

	i, j = x1 + 1, y1 - 1
	while i < 9 and j > 0:
		if diagonal(i, j, x2, y2):
			return True
		i, j = i + 1, j - 1

	i, j = x1 - 1, y1 + 1
	while i > 0 and j < 9:
		if diagonal(i, j, x2, y2):
			return True
		i, j = i - 1, j + 1
	return False


def diagonal(x1, y1, x2, y2):
	if abs(x1 - x2) == abs(y1 - y2):
		return True
	return False


def solve():
	C = [
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 1, 0, 1, 0, 1, 0, 1],
		[0, 1, 0, 1, 0, 1, 0, 1, 0],
		[0, 0, 1, 0, 1, 0, 1, 0, 1],
		[0, 1, 0, 1, 0, 1, 0, 1, 0],
		[0, 0, 1, 0, 1, 0, 1, 0, 1],
		[0, 1, 0, 1, 0, 1, 0, 1, 0],
		[0, 0, 1, 0, 1, 0, 1, 0, 1],
		[0, 1, 0, 1, 0, 1, 0, 1, 0],
	]
	for _ in range(eval(input())):
		x1, y1, x2, y2 = list(map(int, input().split()))

		if any(x > 8 or x < 1 for x in [x1, x2, y1, y2]):
			print(-1)
			continue

		if diagonal(x1, y1, x2, y2):
			print(0)

		elif C[x1][y1] != C[x2][y2]:
			print(-1)
		else:
			print(1)


if __name__ == '__main__':
	limit = 10 ** 15
	solve()