You are given a standard 8 \times 8 chessboard which has exactly 3 pieces placed on it - 2 black rooks and 1 white king. The rows are numbered 1 to 8 from bottom to top, and the columns are numbered 1 to 8 from left to right. The cell at the intersection of the i-th column and j-th row is denoted (i, j) (like the coordinate system on the xy-plane).

Is it possible for the white king to be checkmated by the rooks in exactly one move? It is guaranteed that the initial position of pieces is such that the white king is not under check.

Note that in the given situation, black moves first.

Assume that all the chess rules are to be followed:
Each square can contain at most one piece.
Rooks can only travel in straight lines along the row or column they are placed at, and can't jump over other pieces.
The King can move to any of its 8 adjacent squares.
A piece can't capture a piece of the same color as itself.
After a black makes a move, the white king can capture a rook if it's present on any of the 8 adjacent squares and not protected by the other rook.
The king is said to be in [checkmate] if the king is currently under check and there exists no legal move with the king to escape from the check.
[Stalemate] is considered as a draw for both sides.

For a more detailed explanation of the moves of pieces, along with images, please [click here]. 

Note: The input and output are large, so use fast input-output methods.
In C++, either use printf and scanf, or add the line ios::sync_{with}_stdio(0); cin.tie(0); to the beginning of main to speed up cin and cout. Also, do not use endl, only use '\n'.
In python3/pypy3, add the lines
py
import sys
input = sys.stdin.readline

to the beginning of your code and then use input as you would normally do
In Java, use BufferedReader and PrintWriter

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case contains three lines of input.
- The first line contains two space-separated integers x_{k} and y_{k}, the row and column respectively in which white king is placed.
- The second line contains two space-separated integers x_{1} and y_{1}, the row and column respectively in which the first black rook is placed.
- The third line contains two space-separated integers x_{2} and y_{2}, the row and column respectively in which the second black rook is placed.

------ Output Format ------ 

For each test case, output a single line containing the answer: "YES" if it's possible to checkmate the king in one move and "NO" if not.

You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------ Constraints ------ 

$1 ≤ T ≤ 1.6 \cdot 10^{5}$
$1 ≤ x_{k}, y_{k}, x_{1}, y_{1}, x_{2}, y_{2} ≤ 8$
- Initially the king is not under check, i.e, $x_{k} \neq x_{1}$ and $x_{k} \neq x_{2}$ and $y_{k} \neq y_{1}$ and $y_{k} \neq y_{2}$.
- No two pieces overlap.

------ subtasks ------ 

Subtask #1 (100 points): Original constraints

----- Sample Input 1 ------ 
4
1 1
8 2
7 3
1 8
8 2
8 3
1 1
8 2
2 3
1 1
8 8
8 2

----- Sample Output 1 ------ 
YES
NO
NO
NO
----- explanation 1 ------ 
Test Case $1$: The second rook can be moved to $(7, 1)$, thus checkmating the king.
 
Test Case $2$ and $3$: No possible move exists to checkmate the king. The following images describe why checkmating is impossible in test case $2$:

Test Case $4$: The game can end in a stalemate if the first rook is moved to $(2, 8)$, but there exists no move to checkmate the king.

Difficulty: MEDIUM_HARD
Tags: Complete search

Implementation

Ad-hoc
Skill types: Complete search

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(xk, yk) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	ans = 'NO'
	if not (xk == 1 or yk == 8 or xk == 8 or (yk == 1)):
		ans = 'NO'
	else:
		if xk == 1:
			if (x1 == 2 or x2 == 2) and y1 != y2:
				if abs(y2 - yk) > 1 and abs(y1 - yk) > 1:
					ans = 'YES'
		elif xk == 8:
			if (x1 == 7 or x2 == 7) and y1 != y2:
				if abs(y1 - yk) > 1 and abs(y2 - yk) > 1:
					ans = 'YES'
		if yk == 1:
			if (y1 == 2 or y2 == 2) and x1 != x2:
				if abs(x1 - xk) > 1 and abs(x2 - xk) > 1:
					ans = 'YES'
		elif yk == 8:
			if (y1 == 7 or y2 == 7) and x1 != x2:
				if abs(x2 - xk) > 1 and abs(x1 - xk) > 1:
					ans = 'YES'
	print(ans)


import sys
input = sys.stdin.readline
T = int(input())
for tc in range(T):
	(wkx, wky) = map(int, input().split())
	(br1x, br1y) = map(int, input().split())
	(br2x, br2y) = map(int, input().split())
	if wky == 1 and (br1y == 2 or br2y == 2):
		if br1x != br2x and (abs(br1x - wkx) > 1 and abs(br2x - wkx) > 1):
			print('YES')
		else:
			print('NO')
	elif wky == 8 and (br1y == 7 or br2y == 7):
		if br1x != br2x and (abs(br1x - wkx) > 1 and abs(br2x - wkx) > 1):
			print('YES')
		else:
			print('NO')
	elif wkx == 1 and (br1x == 2 or br2x == 2):
		if br1y != br2y and (abs(br1y - wky) > 1 and abs(br2y - wky) > 1):
			print('YES')
		else:
			print('NO')
	elif wkx == 8 and (br1x == 7 or br2x == 7):
		if br1y != br2y and (abs(br1y - wky) > 1 and abs(br2y - wky) > 1):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def function(xk, yk, x1, y1, x2, y2):
	if xk == 1 or yk == 1 or xk == 8 or (yk == 8):
		if xk == 1:
			if (x1 == 2 or x2 == 2) and y1 != y2:
				if abs(yk - y1) > 1 and abs(yk - y2) > 1:
					return True
		elif xk == 8:
			if (x1 == 7 or x2 == 7) and y1 != y2:
				if abs(yk - y1) > 1 and abs(yk - y2) > 1:
					return True
		if yk == 1:
			if (y1 == 2 or y2 == 2) and x1 != x2:
				if abs(xk - x1) > 1 and abs(xk - x2) > 1:
					return True
		elif yk == 8:
			if (y1 == 7 or y2 == 7) and x1 != x2:
				if abs(xk - x1) > 1 and abs(xk - x2) > 1:
					return True
	else:
		return False
t = int(input())
while t > 0:
	(xk, yk) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	if function(xk, yk, x1, y1, x2, y2):
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	s = 'NO'
	if x == 1:
		if (x1 == 2 or x2 == 2) and y1 != y2:
			if abs(y1 - y) > 1 and abs(y2 - y) > 1:
				s = 'YES'
	elif x == 8:
		if (x1 == 7 or x2 == 7) and y1 != y2:
			if abs(y1 - y) > 1 and abs(y2 - y) > 1:
				s = 'YES'
	if y == 1:
		if (y1 == 2 or y2 == 2) and x1 != x2:
			if abs(x1 - x) > 1 and abs(x2 - x) > 1:
				s = 'YES'
	elif y == 8:
		if (y1 == 7 or y2 == 7) and x1 != x2:
			if abs(x1 - x) > 1 and abs(x2 - x) > 1:
				s = 'YES'
	print(s)


def checkmate(kx, ky, r1x, r1y, r2x, r2y):
	if r1x in [kx, kx + 1, kx - 1] and r1y in [ky, ky + 1, ky - 1]:
		if r1x != r2x or r1y != r2y:
			return False
	elif r2x in [kx, kx + 1, kx - 1] and r2y in [ky, ky + 1, ky - 1]:
		if r2x != r1x or r2y != r1y:
			return False
	elif kx in [1, 8] and set([r1x, r2x]).issubset(set([kx, kx + 1, kx - 1])):
		return True
	elif ky in [1, 8] and set([r1y, r2y]).issubset(set([ky, ky + 1, ky - 1])):
		return True
	return False

def solution():
	(kx, ky) = list(map(int, input().split()))
	(r1x, r1y) = list(map(int, input().split()))
	(r2x, r2y) = list(map(int, input().split()))
	if checkmate(kx, ky, r1x, r1y, r2x, r2y):
		return 'YES'
	if (r1y == r2y and (kx <= r2x and r1x > r2x or (kx >= r2x and r1x < r2x))) == False:
		if checkmate(kx, ky, kx, r1y, r2x, r2y):
			return 'YES'
	if (r1y == r2y and (kx <= r1x and r2x > r1x or (kx >= r1x and r2x < r1x))) == False:
		if checkmate(kx, ky, r1x, r1y, kx, r2y):
			return 'YES'
	if (r1x == r2x and (ky <= r2y and r1y > r2y or (ky >= r2y and r1y < r2y))) == False:
		if checkmate(kx, ky, r1x, ky, r2x, r2y):
			return 'YES'
	if (r1x == r2x and (ky <= r1y and r2y > r1y or (ky >= r1y and r2y < r1y))) == False:
		if checkmate(kx, ky, r1x, r1y, r2x, ky):
			return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solution())


t = int(input())
for i in range(t):
	k = list(map(int, input().split()))
	r1 = list(map(int, input().split()))
	r2 = list(map(int, input().split()))
	if 1 in k or 8 in k:
		if (k[0] == 1 or k[0] == 8) and abs(r1[0] - k[0]) == 1 and (abs(r1[1] - k[1]) > 1) and (abs(r2[1] - k[1]) > 1) and (r1[1] != r2[1]) or ((k[1] == 1 or k[1] == 8) and abs(r1[1] - k[1]) == 1 and (abs(r1[0] - k[0]) > 1) and (abs(r2[0] - k[0]) > 1) and (r1[0] != r2[0])):
			print('YES')
		elif (k[0] == 1 or k[0] == 8) and abs(r2[0] - k[0]) == 1 and (abs(r2[1] - k[1]) > 1) and (abs(r1[1] - k[1]) > 1) and (r1[1] != r2[1]) or ((k[1] == 1 or k[1] == 8) and abs(r2[1] - k[1]) == 1 and (abs(r2[0] - k[0]) > 1) and (abs(r1[0] - k[0]) > 1) and (r1[0] != r2[0])):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
for i in range(t):
	b = False
	k = list(map(int, input().split()))
	r1 = list(map(int, input().split()))
	r2 = list(map(int, input().split()))
	if 1 in k or 8 in k:
		if k[0] == 1:
			if (r1[0] == 2 or r2[0] == 2) and r1[1] != r2[1]:
				if abs(r1[1] - k[1]) > 1 and abs(r2[1] - k[1]) > 1:
					b = True
		elif k[0] == 8:
			if (r1[0] == 7 or r2[0] == 7) and r1[1] != r2[1]:
				if abs(r1[1] - k[1]) > 1 and abs(r2[1] - k[1]) > 1:
					b = True
		if k[1] == 1:
			if (r1[1] == 2 or r2[1] == 2) and r1[0] != r2[0]:
				if abs(r1[0] - k[0]) > 1 and abs(r2[0] - k[0]) > 1:
					b = True
		elif k[1] == 8:
			if (r1[1] == 7 or r2[1] == 7) and r1[0] != r2[0]:
				if abs(r1[0] - k[0]) > 1 and abs(r2[0] - k[0]) > 1:
					b = True
	if b:
		print('YES')
	else:
		print('NO')


import sys

def _can_checkmate_in_column(king, rook_1, rook_2):
	if king[0] not in (1, 8):
		return False
	if abs(rook_2[0] - king[0]) != 1 and abs(rook_1[0] - king[0]) != 1:
		return False
	if abs(rook_2[1] - king[1]) <= 1 or abs(rook_1[1] - king[1]) <= 1:
		return False
	if rook_1[1] == rook_2[1]:
		return False
	return True

def _can_checkmate_in_row(king, rook_1, rook_2):
	return _can_checkmate_in_column(king[::-1], rook_1[::-1], rook_2[::-1])

def can_checkmate(king, rook_1, rook_2):
	if _can_checkmate_in_column(king, rook_1, rook_2):
		return True
	if _can_checkmate_in_row(king, rook_1, rook_2):
		return True
	return False

def _read():
	return sys.stdin.readline()

def read_int():
	return int(_read())

def read_chess_piece_coords():
	(col, row) = map(int, _read().split())
	return (col, row)

def run_case():
	king = read_chess_piece_coords()
	rook_1 = read_chess_piece_coords()
	rook_2 = read_chess_piece_coords()
	print('YES' if can_checkmate(king, rook_1, rook_2) else 'NO')
n_cases = read_int()
for _ in range(n_cases):
	run_case()


import sys
input = sys.stdin.readline
T = int(input())

def checkmate(xk, yk, x1, y1, x2, y2):
	flag = 0
	if xk == 1 and (x1 == 2 or x2 == 2) and (y1 != y2):
		if y1 != yk + 1 and y1 != yk - 1 and (y2 != yk + 1) and (y2 != yk - 1):
			flag = 1
	elif xk == 8 and (x1 == 7 or x2 == 7) and (y1 != y2):
		if y1 != yk + 1 and y1 != yk - 1 and (y2 != yk + 1) and (y2 != yk - 1):
			flag = 1
	elif yk == 1 and (y1 == 2 or y2 == 2) and (x1 != x2):
		if x1 != xk + 1 and x1 != xk - 1 and (x2 != xk + 1) and (x2 != xk - 1):
			flag = 1
	elif yk == 8 and (y1 == 7 or y2 == 7) and (x1 != x2):
		if x1 != xk + 1 and x1 != xk - 1 and (x2 != xk + 1) and (x2 != xk - 1):
			flag = 1
	if flag == 1:
		print('YES')
	else:
		print('NO')
for t in range(T):
	(xk, yk) = input().split(' ')
	(x1, y1) = input().split(' ')
	(x2, y2) = input().split(' ')
	xk = int(xk)
	yk = int(yk)
	x1 = int(x1)
	y1 = int(y1)
	x2 = int(x2)
	y2 = int(y2)
	checkmate(xk, yk, x1, y1, x2, y2)


T = int(input())
for t in range(T):
	king = tuple(map(int, input().split()))
	rook_one = tuple(map(int, input().split()))
	rook_two = tuple(map(int, input().split()))
	x = lambda a: a[0]
	y = lambda a: a[1]
	checkmate = False
	if x(king) == 1 or x(king) == 8:
		if abs(x(king) - x(rook_one)) == 1 or abs(x(king) - x(rook_two)) == 1:
			if abs(y(king) - y(rook_one)) != 1 and abs(y(king) - y(rook_two)) != 1:
				checkmate = True
			if y(rook_one) == y(rook_two):
				checkmate = False
	if y(king) == 1 or y(king) == 8:
		if abs(y(king) - y(rook_one)) == 1 or abs(y(king) - y(rook_two)) == 1:
			if abs(x(king) - x(rook_one)) != 1 and abs(x(king) - x(rook_two)) != 1:
				checkmate = True
			if x(rook_one) == x(rook_two):
				checkmate = False
	if checkmate:
		print('YES')
	else:
		print('NO')


import sys, io, os, time
input = sys.stdin.readline
for tc in range(int(input())):
	(xk, yk) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	if yk == 8:
		(yk, y1, y2) = (9 - yk, 9 - y1, 9 - y2)
	elif xk == 1 and yk != 1:
		(xk, yk, x1, y1, x2, y2) = (yk, xk, y1, x1, y2, x2)
	elif xk == 8 and yk != 1:
		(xk, yk, x1, y1, x2, y2) = (yk, xk, y1, x1, y2, x2)
		(yk, y1, y2) = (9 - yk, 9 - y1, 9 - y2)
	if yk != 1:
		print('NO')
		continue
	if xk == 8:
		(xk, x1, x2) = (9 - xk, 9 - x1, 9 - x2)
	if xk == 1 and yk == 1 and (x1 == 2 or x2 == 2):
		(xk, yk, x1, y1, x2, y2) = (yk, xk, y1, x1, y2, x2)
	if y1 != 2 and y2 != 2:
		print('NO')
		continue
	if xk - 1 <= x1 and x1 <= xk + 1 or (xk - 1 <= x2 and x2 <= xk + 1) or x1 == x2:
		print('NO')
		continue
	print('YES')


import sys
input = sys.stdin.readline
num = int(input())

def posi(x1, y1, x2, y2, xk, yk):
	if xk == 1:
		if (x1 == 2 or x2 == 2) and y1 != y2:
			if abs(y2 - yk) > 1 and abs(y1 - yk) > 1:
				return True
	if xk == 8:
		if (x1 == 7 or x2 == 7) and y1 != y2:
			if abs(y2 - yk) > 1 and abs(y1 - yk) > 1:
				return True
	return False
for x in range(num):
	(xk, yk) = map(int, input().split(' '))
	(x1, y1) = map(int, input().split(' '))
	(x2, y2) = map(int, input().split(' '))
	if xk == 1 or xk == 8 or yk == 1 or (yk == 8):
		if posi(x1, y1, x2, y2, xk, yk) or posi(y1, x1, y2, x2, yk, xk):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for t in range(int(input())):
	(xk, yk) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	if (xk == 1 or xk == 8) and (abs(xk - x1) == 1 or abs(xk - x2) == 1) and (abs(y1 - yk) != 1) and (abs(y2 - yk) != 1) and (y1 != y2):
		print('YES')
	elif (yk == 1 or yk == 8) and (abs(yk - y1) == 1 or abs(yk - y2) == 1) and (abs(x1 - xk) != 1) and (abs(x2 - xk) != 1) and (x1 != x2):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(xk, yk) = map(int, input().split(' '))
	(x1, y1) = map(int, input().split(' '))
	(x2, y2) = map(int, input().split(' '))
	a = 'NO'
	if xk != 1 and yk != 1 and (xk != 8) and (yk != 8):
		a = 'NO'
	else:
		if xk == 1:
			if (x1 == 2 or x2 == 2) and y1 != y2:
				if abs(y1 - yk) > 1 and abs(y2 - yk) > 1:
					a = 'YES'
		elif xk == 8:
			if (x1 == 7 or x2 == 7) and y1 != y2:
				if abs(y1 - yk) > 1 and abs(y2 - yk) > 1:
					a = 'YES'
		if yk == 1:
			if (y1 == 2 or y2 == 2) and x1 != x2:
				if abs(x1 - xk) > 1 and abs(x2 - xk) > 1:
					a = 'YES'
		elif yk == 8:
			if (y1 == 7 or y2 == 7) and x1 != x2:
				if abs(x1 - xk) > 1 and abs(x2 - xk) > 1:
					a = 'YES'
	print(a)


t = int(input())
for i in range(t):
	(x0, y0) = [int(i) for i in input().split()]
	(x1, y1) = [int(j) for j in input().split()]
	(x2, y2) = [int(k) for k in input().split()]
	result = False
	if not (x0 == 1 or x0 == 8 or y0 == 1 or (y0 == 8)):
		result = False
	else:
		if x0 == 1:
			if (x1 == 2 or x2 == 2) and y1 != y2:
				if abs(y1 - y0) > 1 and abs(y2 - y0) > 1:
					result = True
		elif x0 == 8:
			if (x1 == 7 or x2 == 7) and y1 != y2:
				if abs(y1 - y0) > 1 and abs(y2 - y0) > 1:
					result = True
		if y0 == 1:
			if (y1 == 2 or y2 == 2) and x1 != x2:
				if abs(x1 - x0) > 1 and abs(x2 - x0) > 1:
					result = True
		elif y0 == 8:
			if (y1 == 7 or y2 == 7) and x1 != x2:
				if abs(x1 - x0) > 1 and abs(x2 - x0) > 1:
					result = True
	if result and result:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(x1, y1) = map(int, input().split(' '))
	(x2, y2) = map(int, input().split(' '))
	(x3, y3) = map(int, input().split(' '))
	l1 = [x1, x1 + 1, x1 - 1]
	l2 = [y1, y1 + 1, y1 - 1]
	if y1 == 1 and (y2 == 2 or y3 == 2):
		if x2 not in l1 and x3 not in l1 and (x2 != x3):
			print('YES')
		else:
			print('NO')
	elif y1 == 8 and (y2 == 7 or y3 == 7):
		if x2 not in l1 and x3 not in l1 and (x2 != x3):
			print('YES')
		else:
			print('NO')
	elif x1 == 1 and (x2 == 2 or x3 == 2):
		if y2 not in l2 and y3 not in l2 and (y2 != y3):
			print('YES')
		else:
			print('NO')
	elif x1 == 8 and (x2 == 7 or x3 == 7):
		if y2 not in l2 and y3 not in l2 and (y2 != y3):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import math

def solveCheckMate(kx, ky, x1, y1, x2, y2):
	ans = 'NO'
	if kx == 1 or kx == 8 or ky == 1 or (ky == 8):
		if kx == 1:
			if (x1 == 2 or x2 == 2) and y1 != y2:
				if abs(ky - y1) > 1 and abs(ky - y2) > 1:
					ans = 'YES'
		if kx == 8:
			if (x1 == 7 or x2 == 7) and y1 != y2:
				if abs(ky - y1) > 1 and abs(ky - y2) > 1:
					ans = 'YES'
		if ky == 1:
			if (y1 == 2 or y2 == 2) and x1 != x2:
				if abs(kx - x1) > 1 and abs(kx - x2) > 1:
					ans = 'YES'
		if ky == 8:
			if (y1 == 7 or y2 == 7) and x1 != x2:
				if abs(kx - x1) > 1 and abs(kx - x2) > 1:
					ans = 'YES'
	else:
		ans = 'NO'
	return ans
t = int(input())
for _ in range(t):
	(kx, ky) = map(int, input().strip().split(' '))
	(x1, y1) = map(int, input().strip().split(' '))
	(x2, y2) = map(int, input().strip().split(' '))
	print(solveCheckMate(kx, ky, x1, y1, x2, y2))


import sys
input = sys.stdin.readline
for iota in range(int(input())):
	(x_k, y_k) = map(int, input().split())
	(x_1, y_1) = map(int, input().split())
	(x_2, y_2) = map(int, input().split())
	ans = False
	if x_k == 1 and ans == False:
		if x_1 == 2:
			if abs(y_1 - y_k) != 1 and abs(y_2 - y_k) != 1 and (y_2 != y_1):
				ans = True
		elif x_2 == 2:
			if abs(y_2 - y_k) != 1 and abs(y_1 - y_k) != 1 and (y_1 != y_2):
				ans = True
	if x_k == 8 and ans == False:
		if x_1 == 7:
			if abs(y_1 - y_k) != 1 and abs(y_2 - y_k) != 1 and (y_2 != y_1):
				ans = True
		elif x_2 == 7:
			if abs(y_2 - y_k) != 1 and abs(y_1 - y_k) != 1 and (y_1 != y_2):
				ans = True
	if y_k == 1 and ans == False:
		if y_1 == 2:
			if abs(x_1 - x_k) != 1 and abs(x_2 - x_k) != 1 and (x_2 != x_1):
				ans = True
		elif y_2 == 2:
			if abs(x_2 - x_k) != 1 and abs(x_1 - x_k) != 1 and (x_1 != x_2):
				ans = True
	if y_k == 8 and ans == False:
		if y_1 == 7:
			if abs(x_1 - x_k) != 1 and abs(x_2 - x_k) != 1 and (x_2 != x_1):
				ans = True
		elif y_2 == 7:
			if abs(x_2 - x_k) != 1 and abs(x_1 - x_k) != 1 and (x_1 != x_2):
				ans = True
	if ans == True:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def abc():
	(kx, ky) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	if not any([kx == 1, kx == 8, ky == 1, ky == 8]):
		return 'NO'
	if kx == 1:
		if (x1 == 2 or x2 == 2) and y1 != y2:
			if abs(ky - y1) > 1 and abs(ky - y2) > 1:
				return 'YES'
	if kx == 8:
		if (x1 == 7 or x2 == 7) and y1 != y2:
			if abs(ky - y1) > 1 and abs(ky - y2) > 1:
				return 'YES'
	if ky == 1:
		if (y1 == 2 or y2 == 2) and x1 != x2:
			if abs(kx - x1) > 1 and abs(kx - x2) > 1:
				return 'YES'
	if ky == 8:
		if (y1 == 7 or y2 == 7) and x1 != x2:
			if abs(kx - x1) > 1 and abs(kx - x2) > 1:
				return 'YES'
	return 'NO'
try:
	for _ in range(int(input())):
		print(abc())
except:
	pass


def predict(xk, yk, x1, y1, x2, y2):
	if xk == 1 or xk == 8:
		if abs(x1 - xk) == 1 or abs(x2 - xk) == 1:
			if (abs(yk - y1) > 1) & (abs(yk - y2) > 1):
				if y1 != y2:
					return True
	if yk == 1 or yk == 8:
		if abs(y1 - yk) == 1 or abs(y2 - yk) == 1:
			if (abs(xk - x1) > 1) & (abs(xk - x2) > 1):
				if x1 != x2:
					return True
	return False
t = int(input())
for _ in range(t):
	(xk, yk) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	if predict(xk, yk, x1, y1, x2, y2):
		print('YES')
	else:
		print('NO')


import math
import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(Rx, Ry) = input().split()
	(H1x, H1y) = input().split()
	(H2x, H2y) = input().split()
	(Rx, Ry, H1x, H1y, H2x, H2y) = (int(Rx), int(Ry), int(H1x), int(H1y), int(H2x), int(H2y))
	ans = 'NO'
	if H1y != H2y and (abs(Ry - H1y) != 1 and abs(Ry - H2y) != 1):
		if Rx == 1 and (H1x == 2 or H2x == 2):
			ans = 'YES'
		if Rx == 8 and (H1x == 7 or H2x == 7):
			ans = 'YES'
	if H1x != H2x and (abs(Rx - H1x) != 1 and abs(Rx - H2x) != 1):
		if Ry == 1 and (H1y == 2 or H2y == 2):
			ans = 'YES'
		if Ry == 8 and (H1y == 7 or H2y == 7):
			ans = 'YES'
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	t = t - 1
	p = 'NO'
	(xk, yk) = [int(num) for num in input().split()]
	(x1, y1) = [int(num) for num in input().split()]
	(x2, y2) = [int(num) for num in input().split()]
	if (xk < 1 and xk > 8) and (yk < 1 and yk > 8) and (x1 < 1 and x1 > 8) and (y1 < 1 and y1 > 8) and (x2 < 1 and x2 > 8) and (y2 < 1 and x2 > 8):
		p = 'NO'
	elif not (xk == 1 or xk == 8 or yk == 1 or (yk == 8)):
		p = 'NO'
	else:
		if xk == 1:
			if (x1 == 2 or x2 == 2) and y1 != y2:
				if abs(y1 - yk) > 1 and abs(y2 - yk) > 1:
					p = 'YES'
		elif xk == 8:
			if (x1 == 7 or x2 == 7) and y1 != y2:
				if abs(y1 - yk) > 1 and abs(y2 - yk) > 1:
					p = 'YES'
		if yk == 1:
			if (y1 == 2 or y2 == 2) and x1 != x2:
				if abs(x1 - xk) > 1 and abs(x2 - xk) > 1:
					p = 'YES'
		elif yk == 8:
			if (y1 == 7 or y2 == 7) and x1 != x2:
				if abs(x1 - xk) > 1 and abs(x2 - xk) > 1:
					p = 'YES'
	print(p)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	res = 'NO'
	if not (x == 1 or x == 8 or y == 1 or (y == 8)):
		res = 'NO'
	else:
		if x == 1:
			if (a == 2 or c == 2) and b != d:
				if abs(b - y) > 1 and abs(d - y) > 1:
					res = 'YES'
		elif x == 8:
			if (a == 7 or c == 7) and b != d:
				if abs(b - y) > 1 and abs(d - y) > 1:
					res = 'YES'
		if y == 1:
			if (b == 2 or d == 2) and a != c:
				if abs(a - x) > 1 and abs(c - x) > 1:
					res = 'YES'
		elif y == 8:
			if (b == 7 or d == 7) and a != c:
				if (abs(a - x) > 1 and abs(c - x)) > 1:
					res = 'YES'
	print(res)


import sys
test = int(sys.stdin.readline())
for _ in range(test):
	(king_x, king_y) = map(int, sys.stdin.readline().split())
	(rook1_x, rook1_y) = map(int, sys.stdin.readline().split())
	(rook2_x, rook2_y) = map(int, sys.stdin.readline().split())
	if king_y == 1:
		if (rook1_y == 2 or rook2_y == 2) and rook1_x != rook2_x:
			king_range = [king_x, king_x - 1, king_x + 1]
			if rook1_x not in king_range and rook2_x not in king_range:
				print('YES')
				continue
	if king_y == 8:
		if (rook1_y == 7 or rook2_y == 7) and rook1_x != rook2_x:
			king_range = [king_x, king_x - 1, king_x + 1]
			if rook1_x not in king_range and rook2_x not in king_range:
				print('YES')
				continue
	if king_x == 1:
		if (rook1_x == 2 or rook2_x == 2) and rook1_y != rook2_y:
			king_range = [king_y, king_y - 1, king_y + 1]
			if rook1_y not in king_range and rook2_y not in king_range:
				print('YES')
				continue
	if king_x == 8:
		if (rook1_x == 7 or rook2_x == 7) and rook1_y != rook2_y:
			king_range = [king_y, king_y - 1, king_y + 1]
			if rook1_y not in king_range and rook2_y not in king_range:
				print('YES')
				continue
	print('NO')


import sys
input = sys.stdin.readline

def solve():
	(xk, yk) = map(int, input().split())
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	ans = 1
	if 1 < xk < 8 and 1 < yk < 8:
		print('NO')
		return
	else:
		if yk == 1:
			if y1 != 2 and y2 != 2:
				ans = 0
			elif xk > 1 and x1 == xk - 1 or (xk < 8 and x1 == xk + 1):
				ans = 0
			elif xk > 1 and x2 == xk - 1 or (xk < 8 and x2 == xk + 1):
				ans = 0
			elif x1 == x2:
				ans = 0
			else:
				ans = 1
				print('YES')
				return
		if yk == 8:
			if y1 != 7 and y2 != 7:
				ans = 0
			elif xk > 1 and x1 == xk - 1 or (xk < 8 and x1 == xk + 1):
				ans = 0
			elif xk > 1 and x2 == xk - 1 or (xk < 8 and x2 == xk + 1):
				ans = 0
			elif x1 == x2:
				ans = 0
			else:
				ans = 1
				print('YES')
				return
		if xk == 1:
			if x1 != 2 and x2 != 2:
				ans = 0
			elif yk > 1 and y1 == yk - 1 or (yk < 8 and y1 == yk + 1):
				ans = 0
			elif yk > 1 and y2 == yk - 1 or (yk < 8 and y2 == yk + 1):
				ans = 0
			elif y1 == y2:
				ans = 0
			else:
				ans = 1
				print('YES')
				return
		if xk == 8:
			if x1 != 7 and x2 != 7:
				ans = 0
			elif yk > 1 and y1 == yk - 1 or (yk < 8 and y1 == yk + 1):
				ans = 0
			elif yk > 1 and y2 == yk - 1 or (yk < 8 and y2 == yk + 1):
				ans = 0
			elif y1 == y2:
				ans = 0
			else:
				ans = 1
				print('YES')
				return
	if ans:
		print('YES')
	else:
		print('NO')
T = int(input())
for _ in range(T):
	solve()


try:
	s = int(input())
	for j in range(s):
		king = list(map(int, input().split()))
		r1 = list(map(int, input().split()))
		r2 = list(map(int, input().split()))
		ans = 'NO'
		if king[0] == 1:
			if r2[0] == 2 or r1[0] == 2:
				if r2[1] != r1[1] and (king[1] - r2[1] > 1 or r2[1] - king[1] > 1) and (king[1] - r1[1] > 1 or r1[1] - king[1] > 1):
					ans = 'YES'
		if king[0] == 8:
			if r2[0] == 7 or r1[0] == 7:
				if r2[1] != r1[1] and (king[1] - r2[1] > 1 or r2[1] - king[1] > 1) and (king[1] - r1[1] > 1 or r1[1] - king[1] > 1):
					ans = 'YES'
		if king[1] == 1:
			if r2[1] == 2 or r1[1] == 2:
				if r2[0] != r1[0] and (king[0] - r2[0] > 1 or r2[0] - king[0] > 1) and (king[0] - r1[0] > 1 or r1[0] - king[0] > 1):
					ans = 'YES'
		if king[1] == 8:
			if r2[1] == 7 or r1[1] == 7:
				if r2[0] != r1[0] and (king[0] - r2[0] > 1 or r2[0] - king[0] > 1) and (king[0] - r1[0] > 1 or r1[0] - king[0] > 1):
					ans = 'YES'
		print(ans)
except:
	pass


import sys

def left(x, y, a, b, c, d):
	if a == 2 or c == 2:
		if abs(y - b) > 1 and abs(y - d) > 1 and (b != d):
			return 'YES'
	return 'NO'

def right(x, y, a, b, c, d):
	if a == 7 or c == 7:
		if abs(y - b) > 1 and abs(y - d) > 1 and (b != d):
			return 'YES'
	return 'NO'

def top(x, y, a, b, c, d):
	if b == 7 or d == 7:
		if abs(x - a) > 1 and abs(x - c) > 1 and (a != c):
			return 'YES'
	return 'NO'

def bottom(x, y, a, b, c, d):
	if b == 2 or d == 2:
		if abs(x - a) > 1 and abs(x - c) > 1 and (a != c):
			return 'YES'
	return 'NO'

def ansfun():
	(x, y) = map(int, input().split())
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	ans = ''
	if x != 1 and x != 8 and (y != 1) and (y != 8):
		return 'NO'
	else:
		if x == 1:
			ans = left(x, y, a, b, c, d)
			if ans == 'YES':
				return ans
		elif x == 8:
			ans = right(x, y, a, b, c, d)
			if ans == 'YES':
				return ans
		if y == 1:
			ans = bottom(x, y, a, b, c, d)
			if ans == 'YES':
				return ans
		elif y == 8:
			ans = top(x, y, a, b, c, d)
			if ans == 'YES':
				return ans
		return 'NO'
for _ in range(int(input())):
	print(ansfun())


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(xk, yk) = map(int, input().split())
	(xr1, yr1) = map(int, input().split())
	(xr2, yr2) = map(int, input().split())
	possible = 'NO'
	if not (xk == 1 or xk == 8 or yk == 1 or (yk == 8)):
		possible = 'NO'
	else:
		if xk == 1:
			if (xr1 == 2 or xr2 == 2) and yr1 != yr2:
				if abs(yr1 - yk) > 1 and abs(yr2 - yk) > 1:
					possible = 'YES'
		if xk == 8:
			if (xr1 == 7 or xr2 == 7) and yr1 != yr2:
				if abs(yr1 - yk) > 1 and abs(yr2 - yk) > 1:
					possible = 'YES'
		if yk == 1:
			if (yr1 == 2 or yr2 == 2) and xr1 != xr2:
				if abs(xr1 - xk) > 1 and abs(xr2 - xk) > 1:
					possible = 'YES'
		if yk == 8:
			if (yr1 == 7 or yr2 == 7) and xr1 != xr2:
				if abs(xr1 - xk) > 1 and abs(xr2 - xk) > 1:
					possible = 'YES'
	print(possible)