Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.

There are three distinct points - A, B, C in the X-Y plane. Initially, you are located at point A. You want to reach the point C satisfying the following conditions:
You have to go through point B. 
You can move in any of the four axis-parallel directions (+X, -X, +Y, -Y direction). However, you can make at most one turn in the path from A to C. 

Determine if it is possible to reach the destination C satisfying the above conditions.

NOTE:  
One turn means 90 ^ \circ  clockwise or anticlockwise rotation along the direction of movement. For example, if you are moving towards the +X direction, after one turn you can move either in the +Y direction or in the -Y direction. Changing the direction by 180 ^ \circ is not allowed.

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

- The first line of input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains two space-separated integers X_{A}, Y_{A}, denoting the coordinates of the starting point A.
- The second line of each test case contains two space-separated integers X_{B}, Y_{B}, denoting the coordinates of the point B.
- The third line of each test case contains two space-separated integers X_{C}, Y_{C}, denoting the coordinates of the finishing point C.

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

For each test case, print a single line containing one string - "YES"(without quotes) if it is possible to reach the finishing point satisfying the above conditions, otherwise print "NO"(without quotes).

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

$1 ≤ T ≤ 2 \cdot 10^{5}$
$-10^{9} ≤ X_{A}, Y_{A}, X_{B}, Y_{B}, X_{C}, Y_{C} ≤ 10^{9}$
- Three points are pairwise distinct

----- Sample Input 1 ------ 
4
1 1
1 3
3 3
0 0
2 2
3 4
5 2
3 2
1 2
1 1
-1 1
10000 10000

----- Sample Output 1 ------ 
YES
NO
YES
NO
----- explanation 1 ------ 
- Test case $1$:  You start moving in the $+Y$ direction from $A = (1, 1)$, after two-unit steps you reach the point $B = (1, 3)$. Then you make a clockwise turn at point $B$ and start moving towards the $+X$ direction. After two-unit steps, you reach the finishing point $C = (3, 3)$.

- Test case $2$:  There is no possible way to reach the finishing point $C$ satisfying the above conditions. You have to make at least two turns in the path.

- Test case $3$:  You start moving in the $-X$ direction from $A = (5, 2)$ . After 4 unit steps, you reach the finish point $C = (1, 2)$. In the path from $A$ to $C$, you go through the point $B = (3,2)$ and don't make any turn.

Source: codechef | Difficulty: HARD
Tags: Constructive algorithms

Ad-hoc


Solutions:
t = int(input())
for _ in range(t):
	(x1, y1) = map(int, input().split(' '))
	(xb, yb) = map(int, input().split(' '))
	(x3, y3) = map(int, input().split(' '))
	xa = min(x1, x3)
	ya = min(y1, y3)
	xc = max(x1, x3)
	yc = max(y1, y3)
	if xb == xa and ya <= yb <= yc or (yb == yc and xa <= xb <= xc):
		print('YES')
	elif yb == ya and xa <= xb <= xc or (xb == xc and ya <= yb <= yc):
		print('YES')
	else:
		print('NO')


for T in range(int(input())):
	(x1, y1) = [int(z) for z in input().split()]
	(x2, y2) = [int(z) for z in input().split()]
	(x3, y3) = [int(z) for z in input().split()]
	s = 'NO'
	if x1 > x3:
		(x1, x3) = (x3, x1)
	if y1 > y3:
		(y1, y3) = (y3, y1)
	if x1 == x3:
		if x1 == x2 and y1 < y2 < y3:
			s = 'YES'
	elif y1 == y3:
		if y1 == y2 and x1 < x2 < x3:
			s = 'YES'
	elif x1 <= x2 <= x3 and y1 <= y2 <= y3 and (x1 == x2 or x2 == x3 or y1 == y2 or (y2 == y3)):
		s = 'YES'
	print(s)


import sys
try:

	def fun(xa, ya, xb, yb, xc, yc):
		(left, right) = (min(xa, xc), max(xa, xc))
		(bottom, top) = (min(ya, yc), max(ya, yc))
		ans = False
		if left <= xb and xb <= right:
			if yb == top or yb == bottom:
				ans = True
		if bottom <= yb and yb <= top:
			if xb == left or xb == right:
				ans = True
		if ans:
			print('YES')
		else:
			print('NO')

	def get_ints():
		return map(int, sys.stdin.readline().strip().split())
	for _ in range(int(input())):
		(xa, ya) = get_ints()
		(xb, yb) = get_ints()
		(xc, yc) = get_ints()
		fun(xa, ya, xb, yb, xc, yc)
except:
	pass


t = int(input())
while t:
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(cx, cy) = map(int, input().split())
	condition1 = ax == bx and cy == by
	condition2 = ay == by and cx == bx
	condition3 = ax == bx and cx == bx and (bx > ax and bx < cx or (bx < ax and bx > cx))
	condition4 = ay == by and cy == by and (by > ay and by < cy or (by < ay and by > cy))
	condition5 = (ax == bx or cx == bx) and (by > ay and by < cy or (by < ay and by > cy))
	condition6 = (ay == by or cy == by) and (bx > ax and bx < cx or (bx < ax and bx > cx))
	if condition1 or condition2 or condition3 or condition4 or condition5 or condition6:
		print('YES')
	else:
		print('NO')
	t -= 1


import sys

def inp():
	return sys.stdin.readline()
for _ in range(int(input())):
	(xa, ya) = map(int, inp().split())
	(xb, yb) = map(int, inp().split())
	(xc, yc) = map(int, inp().split())
	(left, right) = (min(xa, xc), max(xa, xc))
	(bottom, top) = (min(ya, yc), max(ya, yc))
	ans = False
	if left <= xb and xb <= right:
		if yb == bottom or yb == top:
			ans = True
	if bottom <= yb and yb <= top:
		if xb == left or xb == right:
			ans = True
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	(left, right) = (min(xa, xc), max(xa, xc))
	(bottom, top) = (min(ya, yc), max(ya, yc))
	ans = False
	if left <= xb and xb <= right:
		if yb == bottom or yb == top:
			ans = True
	if bottom <= yb and yb <= top:
		if xb == left or xb == right:
			ans = True
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = list(map(int, input().split()))
	if (l2[0] >= l1[0] and l2[0] <= l3[0] or (l2[0] <= l1[0] and l2[0] >= l3[0])) and (l2[1] >= l1[1] and l2[1] <= l3[1] or (l2[1] <= l1[1] and l2[1] >= l3[1])):
		if l2[0] == l3[0] or l2[1] == l3[1]:
			print('YES')
		elif l2[0] == l1[0] or l2[1] == l1[1]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


q = int(input())
for i in range(q):
	(x_a, y_a) = map(int, input().split())
	(x_b, y_b) = map(int, input().split())
	(x_c, y_c) = map(int, input().split())
	if x_c == x_b and (y_a >= y_b and y_b > y_c or (y_a <= y_b and y_b < y_c)) or (y_c == y_b and (x_a >= x_b and x_b > x_c or (x_a <= x_b and x_b < x_c))):
		print('YES')
	elif x_a == x_b and (y_a > y_b and y_b >= y_c or (y_a < y_b and y_b <= y_c)) or (y_a == y_b and (x_a > x_b and x_b >= x_c or (x_a < x_b and x_b <= x_c))):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	turn = 0
	dirx = 0
	diry = 0
	if xb > xa:
		dirx = 1
	elif xb < xa:
		dirx = -1
	else:
		dirx = 0
	if yb > ya:
		diry = 1
	elif yb < ya:
		diry = -1
	else:
		diry = 0
	if dirx != 0 and diry != 0:
		turn += 1
	ans = []
	dirx2 = diry2 = 0
	if xc > xb:
		if dirx == -1:
			ans.append('NO')
		dirx2 = 1
	elif xc < xb:
		if dirx == 1:
			ans.append('NO')
		dirx2 = -1
	if yc > yb:
		if diry == -1:
			ans.append('NO')
		diry2 = 1
	elif yc < yb:
		if diry == 1:
			ans.append('NO')
		diry2 = -1
	if len(ans) != 0:
		print('NO')
	elif turn == 1 and (dirx2 != 0 and diry2 != 0):
		print('NO')
	else:
		print('YES')


t = int(input())
while t:
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	left = min(xa, xc)
	right = max(xa, xc)
	top = max(ya, yc)
	ans = False
	bottom = min(ya, yc)
	if left <= xb and xb <= right:
		if yb == top or yb == bottom:
			ans = True
	if bottom <= yb and yb <= top:
		if xb == left or xb == right:
			ans = True
	if ans:
		print('YES')
	else:
		print('NO')
	t -= 1


for i in range(int(input())):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	if xa == xb:
		if yc >= ya and yb >= ya or (yc <= ya and yb <= ya):
			if abs(yc - ya) >= abs(yb - ya):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	elif xc == xb:
		if yc >= ya and yb >= ya or (yc <= ya and yb <= ya):
			if abs(yc - ya) >= abs(yb - ya):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	elif yb == yc:
		if xc >= xa and xb >= xa or (xc <= xa and xb <= xa):
			if abs(xc - xa) >= abs(xb - xa):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	elif yb == ya:
		if xc >= xa and xb >= xa or (xc <= xa and xb <= xa):
			if abs(xc - xa) >= abs(xb - xa):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	count = 0
	if a[0] == b[0]:
		if a[1] > b[1]:
			if c[1] <= b[1]:
				print('YES')
			else:
				print('NO')
		elif c[1] >= b[1]:
			print('YES')
		else:
			print('NO')
	elif a[1] == b[1]:
		if a[0] > b[0]:
			if c[0] <= b[0]:
				print('YES')
			else:
				print('NO')
		elif c[0] >= b[0]:
			print('YES')
		else:
			print('NO')
	elif b[0] == c[0]:
		if b[1] >= a[1]:
			if c[1] > b[1]:
				print('YES')
			else:
				print('NO')
		elif c[1] < b[1]:
			print('YES')
		else:
			print('NO')
	elif b[1] == c[1]:
		if b[0] >= a[0]:
			if c[0] > b[0]:
				print('YES')
			else:
				print('NO')
		elif c[0] < b[0]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


testCases = int(input())
for i in range(testCases):
	(x1, y1) = list(map(int, input().split()))
	(x2, y2) = list(map(int, input().split()))
	(x3, y3) = list(map(int, input().split()))
	if (x1 <= x2 <= x3 or x3 <= x2 <= x1) and (y1 <= y2 <= y3 or y3 <= y2 <= y1):
		if x1 == x2 or y1 == y2 or x3 == x2 or (y3 == y2):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
for j in range(t):
	(x1, y1) = map(int, input().split())
	(x2, y2) = map(int, input().split())
	(x3, y3) = map(int, input().split())
	trn = 0
	if x1 != x2 and y1 != y2:
		trn = 1
	if trn == 1:
		if x3 == x2 or y3 == y2:
			if x3 == x2:
				if y2 > y1 and y3 < y2:
					print('NO')
					continue
				if y2 < y1 and y3 > y2:
					print('NO')
					continue
			if y3 == y2:
				if x2 > x1 and x3 < x2:
					print('NO')
					continue
				if x2 < x1 and x3 > x2:
					print('NO')
					continue
			print('YES')
			continue
		else:
			print('NO')
			continue
	else:
		if x1 == x2:
			if y2 > y1 and y3 < y2:
				print('NO')
				continue
			if y2 < y1 and y3 > y2:
				print('NO')
				continue
			print('YES')
			continue
		if y1 == y2:
			if x2 > x1 and x3 < x2:
				print('NO')
				continue
			if x2 < x1 and x3 > x2:
				print('NO')
				continue
			print('YES')
			continue


for _ in range(int(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:
		if y2 == y1 and x3 <= x2 <= x1:
			print('YES')
			continue
		if x2 == x1 and y3 >= y2 >= y1:
			print('YES')
			continue
		if y3 == y2 and x3 <= x2 <= x1:
			print('YES')
			continue
		if x3 == x2 and y3 >= y2 >= y1:
			print('YES')
			continue
	if x1 > x3 and y1 > y3:
		if y2 == y1 and x3 <= x2 <= x1:
			print('YES')
			continue
		if x2 == x1 and y1 >= y2 >= y3:
			print('YES')
			continue
		if y3 == y2 and x3 <= x2 <= x1:
			print('YES')
			continue
		if x3 == x2 and y1 >= y2 >= y3:
			print('YES')
			continue
	if x1 < x3 and y1 < y3:
		if y2 == y1 and x1 <= x2 <= x3:
			print('YES')
			continue
		if x2 == x1 and y3 >= y2 >= y1:
			print('YES')
			continue
		if y3 == y2 and x1 <= x2 <= x3:
			print('YES')
			continue
		if x3 == x2 and y3 >= y2 >= y1:
			print('YES')
			continue
	if x1 < x3 and y1 > y3:
		if y2 == y1 and x1 <= x2 <= x3:
			print('YES')
			continue
		if x2 == x1 and y1 >= y2 >= y3:
			print('YES')
			continue
		if y3 == y2 and x1 <= x2 <= x3:
			print('YES')
			continue
		if x3 == x2 and y1 >= y2 >= y3:
			print('YES')
			continue
	if x1 == x2 == x3 or y1 == y2 == y3:
		if x1 <= x2 <= x3 or x3 <= x2 <= x1:
			print('YES')
			continue
		if y1 >= y2 >= y3 or y3 >= y2 >= y1:
			print('YES')
			continue
	else:
		print('NO')


cases = int(input())
for _ in range(cases):
	(x1, y1) = [int(x) for x in input().split()]
	(x2, y2) = [int(x) for x in input().split()]
	(x3, y3) = [int(x) for x in input().split()]
	if x1 > x3:
		(x1, x3) = (x3, x1)
	if y1 > y3:
		(y1, y3) = (y3, y1)
	if x1 == x3:
		if x1 == x2 and y1 < y2 < y3:
			print('YES')
		else:
			print('NO')
	elif y1 == y3:
		if y1 == y2 and x1 < x2 < x3:
			print('YES')
		else:
			print('NO')
	elif x1 <= x2 <= x3 and y1 <= y2 <= y3 and (x1 == x2 or x2 == x3 or y1 == y2 or (y2 == y3)):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = list(map(int, input().split(' ')))
	l = min(a[0], c[0])
	r = max(a[0], c[0])
	t = max(a[1], c[1])
	bt = min(a[1], c[1])
	f = 0
	if l <= b[0] and b[0] <= r:
		if b[1] == t or b[1] == bt:
			f = 1
	if bt <= b[1] and b[1] <= t:
		if b[0] == l or b[0] == r:
			f = 1
	if f == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
	if (a[0] == b[0] or b[0] == c[0]) and (a[1] < b[1] <= c[1] or a[1] > b[1] >= c[1]):
		print('YES')
	elif (a[1] == b[1] or b[1] == c[1]) and (a[0] < b[0] <= c[0] or a[0] > b[0] >= c[0]):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = list(map(int, input().split()))
	ans = 'NO'
	if B[0] == A[0] or B[0] == C[0]:
		if B[1] >= min(A[1], C[1]) and B[1] <= max(A[1], C[1]):
			ans = 'YES'
	elif B[1] == A[1] or B[1] == C[1]:
		if B[0] >= min(A[0], C[0]) and B[0] <= max(A[0], C[0]):
			ans = 'YES'
	print(ans)


T = int(input())
for i in range(T):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = [int(i) for i in input().split()]
	(l, r) = (min(xa, xc), max(xa, xc))
	(t, b) = (max(ya, yc), min(ya, yc))
	Flag = 0
	if l <= xb and xb <= r:
		if yb == b or yb == t:
			Flag = 1
	if b <= yb and yb <= t:
		if xb == l or xb == r:
			Flag = 1
	if Flag:
		print('YES')
	else:
		print('NO')


cases = int(input())
for _ in range(cases):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	if ((xa <= xb <= xc or xa >= xb >= xc) and (ya <= yb <= yc or ya >= yb >= yc)) and ((xb == xa or xb == xc) or (yb == ya or yb == yc)):
		print('YES')
	else:
		print('NO')


x = int(input())
for i in range(x):
	a = input().split()
	b = input().split()
	c = input().split()
	ax = int(a[0])
	ay = int(a[1])
	bx = int(b[0])
	by = int(b[1])
	cx = int(c[0])
	cy = int(c[1])
	if min(ay, cy) <= by <= max(ay, cy) and bx == min(ax, bx) or (by == min(cy, ay) and min(ax, bx) <= bx <= max(ax, bx)) or (bx == max(ax, cx) and min(ay, cy) <= by <= max(ay, cy)) or (by == max(cy, ay) and min(ax, cx) <= bx <= max(ax, cx)):
		print('YES')
	else:
		print('NO')


t = int(input())
for t in range(t):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	c = False
	d = max(xc, xa)
	e = min(xc, xa)
	f = max(yc, ya)
	g = min(yc, ya)
	if e <= xb and xb <= d:
		if yb == f or yb == g:
			c = True
	if g <= yb and yb <= f:
		if xb == d or xb == e:
			c = True
	if c == True:
		print('YES')
	else:
		print('NO')


def solve():
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(cx, cy) = map(int, input().split())
	if not (min(ax, cx) <= bx <= max(ax, cx) and min(ay, cy) <= by <= max(ay, cy)):
		print('NO')
		return
	if ax == bx or ay == by:
		print('YES')
		return
	if cx == bx or cy == by:
		print('YES')
		return
	print('NO')
for _ in range(int(input())):
	solve()


t = int(input())
for tc in range(t):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	(right, left) = (max(xa, xc), min(xa, xc))
	(top, botm) = (max(ya, yc), min(ya, yc))
	if left <= xb and xb <= right:
		if yb == top or yb == botm:
			print('YES')
			continue
	if botm <= yb and yb <= top:
		if xb == right or xb == left:
			print('YES')
			continue
	print('NO')


for _ in range(int(input())):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	xma = max(xa, xc)
	xmi = min(xa, xc)
	ymi = min(ya, yc)
	yma = max(ya, yc)
	c = 0
	if (yb == yc or yb == ya) and xmi <= xb and (xb <= xma):
		c += 1
	elif (xa == xb or xc == xb) and ymi <= yb and (yb <= yma):
		c += 1
	if c > 0:
		print('YES')
	else:
		print('NO')


T = int(input())
for t in range(0, T):
	(XA, YA) = map(int, input().split())
	(XB, YB) = map(int, input().split())
	(XC, YC) = map(int, input().split())
	left = min(XA, XC)
	right = max(XA, XC)
	top = max(YC, YA)
	down = min(YC, YA)
	if XB == left or XB == right:
		if YB >= down and YB <= top:
			print('YES')
		else:
			print('NO')
	elif YB == top or YB == down:
		if XB >= left and XB <= right:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
for i in range(0, t):
	(Xa, Ya) = map(int, input().split())
	(Xb, Yb) = map(int, input().split())
	(Xc, Yc) = map(int, input().split())
	right = max(Xa, Xc)
	left = min(Xa, Xc)
	bottom = min(Ya, Yc)
	top = max(Ya, Yc)
	ans = False
	if left <= Xb and Xb <= right:
		if Yb == top or Yb == bottom:
			ans = 'True'
	if bottom <= Yb and Yb <= top:
		if Xb == left or Xb == right:
			ans = 'True'
	print('YES' if ans else 'NO')


t = int(input())
for i in range(t):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	left = min(xa, xc)
	right = max(xa, xc)
	top = max(ya, yc)
	bottom = min(ya, yc)
	flag = 0
	if left <= xb and xb <= right:
		if yb == bottom or yb == top:
			flag = 1
	if bottom <= yb and yb <= top:
		if xb == left or xb == right:
			flag = 1
	if flag == 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	x = [a[0], c[0]]
	x.sort()
	y = [a[1], c[1]]
	y.sort()
	if b[0] == a[0] or b[0] == c[0]:
		if b[1] >= min(a[1], c[1]) and b[1] <= max(a[1], c[1]):
			print('YES')
		else:
			print('NO')
	elif b[1] == a[1] or b[1] == c[1]:
		if b[0] >= min(a[0], c[0]) and b[0] <= max(a[0], c[0]):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(p, q) = map(int, input().split())
	(x, y) = map(int, input().split())
	t = 1
	if a == p or b == q:
		t = 1
	else:
		t = 0
	if t == 0:
		if p == x:
			if (b - q) * (q - y) > 0:
				t = 0
			else:
				t = -1
		elif q == y:
			if (a - p) * (p - x) > 0:
				t = 0
			else:
				t = -1
		else:
			t = -1
	if t == 1:
		if a == p:
			if (b - q) * (q - y) >= 0:
				t = t
			else:
				t = -1
		if b == q:
			if (a - p) * (p - x) >= 0:
				t = t
			else:
				t = -1
	if t == -1:
		print('NO')
	else:
		print('YES')


import sys

def inp():
	return sys.stdin.readline()
for _ in range(int(inp())):
	(ax, ay) = map(int, inp().split())
	(bx, by) = map(int, inp().split())
	(cx, cy) = map(int, inp().split())
	if (ax == bx or bx == cx) and (ay <= by <= cy or cy <= by <= ay):
		print('YES')
	elif (ay == by or by == cy) and (ax <= bx <= cx or cx <= bx <= ax):
		print('YES')
	else:
		print('NO')


def sol(a, b, c):
	left = min(a[0], c[0])
	right = max(a[0], c[0])
	bottom = min(a[1], c[1])
	top = max(a[1], c[1])
	if left <= b[0] <= right:
		if b[1] == top or b[1] == bottom:
			return True
	if bottom <= b[1] <= top:
		if b[0] == left or b[0] == right:
			return True
	return False
for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	if sol(a, b, c):
		print('YES')
	else:
		print('NO')


for tcase in range(int(input())):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	if (xb - xa) * (xb - xc) > 0:
		print('NO')
	elif (yb - ya) * (yb - yc) > 0:
		print('NO')
	elif (xb - xa) * (xb - xc) == 0:
		print('YES')
	elif (yb - ya) * (yb - yc) == 0:
		print('YES')
	else:
		print('NO')


def prog_name():
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	cnt = 0
	if xa == xb and ya == yb:
		print('YES')
	elif xa == xb:
		if yb >= ya and yc >= yb:
			print('YES')
		elif yb <= ya and yc <= yb:
			print('YES')
		else:
			print('NO')
	elif ya == yb:
		if xb >= xa and xc >= xb:
			print('YES')
		elif xb <= xa and xc <= xb:
			print('YES')
		else:
			print('NO')
	elif yb == yc or xb == xc:
		if xb == xc:
			if yb >= ya and yc >= yb:
				print('YES')
			elif yb <= ya and yc <= yb:
				print('YES')
			else:
				print('NO')
		elif xb >= xa and xc >= xb:
			print('YES')
		elif xb <= xa and xc <= xb:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
T = int(input())
for unique in range(T):
	prog_name()


from sys import stdin
input = stdin.readline

def answer():
	if xa == xb or xb == xc:
		if ya <= yb and yb <= yc:
			return 'YES'
		if ya >= yb and yb >= yc:
			return 'YES'
	if ya == yb or yb == yc:
		if xa <= xb and xb <= xc:
			return 'YES'
		if xa >= xb and xb >= xc:
			return 'YES'
	return 'NO'
for T in range(int(input())):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	print(answer())


t = int(input())
while t > 0:
	(x1, y1) = [int(x) for x in input().split()]
	(x2, y2) = [int(x) for x in input().split()]
	(x3, y3) = [int(x) for x in input().split()]
	flag = False
	if x1 - x2 == 0:
		if y2 >= y1 and y3 >= y2:
			flag = True
		elif y2 < y1 and y3 < y2:
			flag = True
	elif y1 - y2 == 0:
		if x2 >= x1 and x3 >= x2:
			flag = True
		elif x2 < x1 and x3 < x2:
			flag = True
	elif y2 - y3 == 0:
		if x2 >= x1 and x3 > x2:
			flag = True
		elif x2 < x1 and x3 < x2:
			flag = True
	elif x2 - x3 == 0:
		if y2 >= y1 and y3 >= y2:
			flag = True
		elif y2 < y1 and y3 < y2:
			flag = True
	if flag == True:
		print('YES')
	else:
		print('NO')
	t -= 1


tC = int(input())
for __ in range(tC):
	(Ax, Ay) = map(int, input().split())
	(Bx, By) = map(int, input().split())
	(Cx, Cy) = map(int, input().split())
	if Ax == Bx and (Ay <= By <= Cy or Ay >= By >= Cy):
		print('YES')
		continue
	if Ay == By and (Ax <= Bx <= Cx or Ax >= Bx >= Cx):
		print('YES')
		continue
	if Bx == Cx and (Ay <= By <= Cy or Ay >= By >= Cy):
		print('YES')
		continue
	if By == Cy and (Ax <= Bx <= Cx or Ax >= Bx >= Cx):
		print('YES')
		continue
	print('NO')


k = int(input())
for i in range(k):
	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] or a[0] == b[0] or b[0] == c[0]:
		if a[1] <= b[1] <= c[1] or a[1] >= b[1] >= c[1]:
			print('YES')
		else:
			print('NO')
	elif a[1] == b[1] == c[1] or a[1] == b[1] or b[1] == c[1]:
		if a[0] <= b[0] <= c[0] or a[0] >= b[0] >= c[0]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	while True:
		if xa == xb:
			if yb == yc:
				print('YES')
				break
			elif xb == xc:
				if yb < ya and yb > yc:
					print('YES')
					break
				elif yb > ya and yc > yb:
					print('YES')
					break
				else:
					print('No')
					break
			elif ya > yb:
				if yc > yb:
					print('NO')
					brreak
				else:
					print('YES')
					break
			elif yc < yb:
				print('NO')
				break
			else:
				print('YES')
				break
		elif ya == yb:
			if xb == xc:
				print('YES')
				break
			elif yb == yc:
				if xb > xa and xc > xb:
					print('YES')
					break
				elif xb < xa and xc < xb:
					print('YES')
					break
				else:
					print('NO')
					break
			elif xc < xb:
				print('NO')
				break
			else:
				print('YES')
				break
		elif xb > xa:
			if yb > ya:
				if xc == xb and yc > yb:
					print('YES')
					break
				elif yb == yc and xc > xb:
					print('YES')
					break
				else:
					print('NO')
					break
			elif xc == xb and yc < yb:
				print('Yes')
				break
			elif yb == yc and xc > xb:
				print('YES')
				break
			else:
				print('NO')
				break
		elif yb > ya:
			if xc == xb and yc > yb:
				print('YES')
				break
			elif yb == yc and xc < xb:
				print('YES')
				break
			else:
				print('NO')
				break
		elif xb == xc and yb > yc:
			print('YES')
			break
		elif yb == yc and xc < xb:
			print('YES')
			break
		else:
			print('No')
			break


def hello():
	t = int(input())
	for i in range(t):
		A = list(map(int, input().split(' ')))
		B = list(map(int, input().split(' ')))
		C = list(map(int, input().split(' ')))
		if A[0] == B[0] and A[1] == B[1]:
			print('YES')
		elif A[0] == C[0] and A[1] == C[1]:
			print('YES')
		elif B[0] == C[0] and B[1] == C[1]:
			print('YES')
		elif A[0] == B[0]:
			if A[1] > B[1] and B[1] >= C[1]:
				print('YES')
			elif A[1] < B[1] and B[1] <= C[1]:
				print('YES')
			else:
				print('NO')
		elif A[1] == B[1]:
			if A[0] > B[0] and B[0] >= C[0]:
				print('YES')
			elif A[0] < B[0] and B[0] <= C[0]:
				print('YES')
			else:
				print('NO')
		elif B[0] == C[0]:
			if A[1] > B[1] and B[1] > C[1]:
				print('YES')
			elif A[1] < B[1] and B[1] < C[1]:
				print('YES')
			else:
				print('NO')
		elif B[1] == C[1]:
			if A[0] > B[0] and B[0] > C[0]:
				print('YES')
			elif A[0] < B[0] and B[0] < C[0]:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
hello()


for t in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	ab = [b[0] - a[0], b[1] - a[1]]
	bc = [c[0] - b[0], c[1] - b[1]]
	turn = 0
	if ab[0] * bc[0] + ab[1] * bc[1] < 0:
		print('NO')
	else:
		if a[0] != b[0] and a[1] != b[1]:
			turn += 1
			if b[0] != c[0] and b[1] != c[1]:
				turn += 1
		elif a[1] == b[1] and b[1] == c[1]:
			turn = 0
		elif a[0] == b[0] and b[0] == c[0]:
			turn = 0
		elif a[1] == b[1] and b[0] == c[0]:
			turn += 1
		elif a[0] == b[0] and b[1] == c[1]:
			turn += 1
		else:
			turn += 1
		if turn < 2:
			print('YES')
		else:
			print('NO')


for i in range(int(input())):
	(ax, ay) = map(int, input().split())
	(bx, by) = map(int, input().split())
	(cx, cy) = map(int, input().split())
	if ay == by:
		if bx > ax and cx >= bx:
			print('YES')
		elif bx < ax and cx <= bx:
			print('YES')
		elif ax == bx:
			print('YES')
		else:
			print('NO')
	elif ax == bx:
		if by > ay and cy >= by:
			print('YES')
		elif by < ay and cy <= by:
			print('YES')
		elif ay == by:
			print('YES')
		else:
			print('NO')
	elif ax != bx and ay != by:
		if bx >= ax and by >= ay:
			if cx >= bx and cy == by:
				print('YES')
			elif cy >= by and cx == bx:
				print('YES')
			else:
				print('NO')
		elif bx >= ax and by <= ay:
			if cy <= by and cx == bx:
				print('YES')
			elif cx >= bx and cy == by:
				print('YES')
			else:
				print('NO')
		elif bx <= ax and by >= ay:
			if cx <= bx and cy == by:
				print('YES')
			elif cy >= by and cx == bx:
				print('YES')
			else:
				print('NO')
		elif bx <= ax and by <= ay:
			if cx <= bx and cy == by:
				print('YES')
			elif cy <= by and cx == bx:
				print('YES')
			else:
				print('NO')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	if (xc >= xa and yc >= ya) and (xb >= xa and xb <= xc) and (yb >= ya and yb <= yc):
		if xa - xb == 0 or xc - xb == 0 or yb - yc == 0 or (yb - ya == 0):
			print('YES')
		else:
			print('NO')
	elif (xc <= xa and yc >= ya) and (xb <= xa and xc <= xb) and (yb >= ya and yb <= yc):
		if xa - xb == 0 or xc - xb == 0 or yb - yc == 0 or (yb - ya == 0):
			print('YES')
		else:
			print('NO')
	elif (xc <= xa and yc <= ya) and (xb <= xa and xc <= xb) and (yb <= ya and yc <= yb):
		if xa - xb == 0 or xc - xb == 0 or yb - yc == 0 or (yb - ya == 0):
			print('YES')
		else:
			print('NO')
	elif (xc >= xa and yc <= ya) and (xb >= xa and xb <= xc) and (yb <= ya and yc <= yb):
		if xa - xb == 0 or xc - xb == 0 or yb - yc == 0 or (yb - ya == 0):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for t in range(int(input())):
	An = list(map(int, input().split()))
	Bn = list(map(int, input().split()))
	Cn = list(map(int, input().split()))
	if An[0] == Bn[0] == Cn[0] or An[0] == Bn[0] or Bn[0] == Cn[0]:
		if An[1] <= Bn[1] <= Cn[1] or An[1] >= Bn[1] >= Cn[1]:
			print('YES')
		else:
			print('NO')
	elif An[1] == Bn[1] == Cn[1] or An[1] == Bn[1] or Bn[1] == Cn[1]:
		if An[0] <= Bn[0] <= Cn[0] or An[0] >= Bn[0] >= Cn[0]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


try:
	t = int(input())
	for i in range(t):
		a = list(map(int, input().split()))
		a1 = list(map(int, input().split()))
		a2 = list(map(int, input().split()))
		if a[0] == a1[0] == a2[0] or a[0] == a1[0] or a1[0] == a2[0]:
			if a[1] <= a1[1] <= a2[1] or a[1] >= a1[1] >= a2[1]:
				print('YES')
			else:
				print('NO')
		elif a[1] == a1[1] == a2[1] or a[1] == a1[1] or a1[1] == a2[1]:
			if a[0] <= a1[0] <= a2[0] or a[0] >= a1[0] >= a2[0]:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
except ExceptionError:
	print(ExceptionError)


for _ in range(int(input())):
	coo1 = list(map(int, input().split()))
	coo2 = list(map(int, input().split()))
	coo3 = list(map(int, input().split()))
	if coo1[0] == coo2[0] == coo3[0] or coo1[0] == coo2[0] or coo2[0] == coo3[0]:
		if coo1[1] <= coo2[1] <= coo3[1] or coo1[1] >= coo2[1] >= coo3[1]:
			print('YES')
		else:
			print('NO')
	elif coo1[1] == coo2[1] == coo3[1] or coo1[1] == coo2[1] or coo2[1] == coo3[1]:
		if coo1[0] <= coo2[0] <= coo3[0] or coo1[0] >= coo2[0] >= coo3[0]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	if xa == xb or xb == xc:
		dab = abs(ya - yb)
		dbc = abs(yb - yc)
		dac = abs(ya - yc)
		if dac == dab + dbc:
			print('YES')
			continue
	if ya == yb or yb == yc:
		dab = abs(xa - xb)
		dbc = abs(xb - xc)
		dac = abs(xa - xc)
		if dac == dab + dbc:
			print('YES')
			continue
	print('NO')


for i in range(int(input())):
	(xa, ya) = list(map(int, input().split()))
	(xb, yb) = list(map(int, input().split()))
	(xc, yc) = list(map(int, input().split()))
	t = 'NO'
	if xb == xa:
		if ya > yc:
			if ya >= yb >= yc:
				t = 'YES'
		elif yc >= yb >= ya:
			t = 'YES'
	elif yb == ya:
		if xc > xa:
			if xc >= xb >= xa:
				t = 'YES'
		elif xa >= xb >= xc:
			t = 'YES'
	elif xb == xc:
		if ya > yc:
			if ya >= yb >= yc:
				t = 'YES'
		elif yc >= yb >= ya:
			t = 'YES'
	elif yb == yc:
		if xc > xa:
			if xc >= xb >= xa:
				t = 'YES'
		elif xa >= xb >= xc:
			t = 'YES'
	print(t)


from sys import stdin, stdout
for t in range(int(input())):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	if b[0] == c[0]:
		if b[1] > c[1]:
			if a[1] >= b[1]:
				print('YES')
			else:
				print('NO')
		elif b[1] < c[1]:
			if a[1] <= b[1]:
				print('YES')
			else:
				print('NO')
	elif b[1] == c[1]:
		if b[0] > c[0]:
			if a[0] >= b[0]:
				print('YES')
			else:
				print('NO')
		elif b[0] < c[0]:
			if a[0] <= b[0]:
				print('YES')
			else:
				print('NO')
	elif a[0] == b[0]:
		if b[1] > a[1]:
			if c[1] >= b[1]:
				print('YES')
			else:
				print('NO')
		elif b[1] < a[1]:
			if c[1] <= b[1]:
				print('YES')
			else:
				print('NO')
	elif a[1] == b[1]:
		if b[0] > a[0]:
			if c[0] >= b[0]:
				print('YES')
			else:
				print('NO')
		elif b[0] < a[0]:
			if c[0] <= b[0]:
				print('YES')
			else:
				print('NO')
	else:
		print('NO')


for _ in range(int(input())):
	arr = list(map(int, input().split()))
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	C = 0
	if C == 1:
		break
	elif arr[0] == arr1[0] == arr2[0] or arr[0] == arr1[0] or arr1[0] == arr2[0]:
		if arr[1] <= arr1[1] <= arr2[1] or arr[1] >= arr1[1] >= arr2[1]:
			print('YES')
		else:
			print('NO')
	elif arr[1] == arr1[1] == arr2[1] or arr[1] == arr1[1] or arr1[1] == arr2[1]:
		if arr[0] <= arr1[0] <= arr2[0] or arr[0] >= arr1[0] >= arr2[0]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def sum(a, b):
	return a + b

def mul(a, b):
	return a * b
for T in range(int(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] or A[0] == B[0] or B[0] == C[0]:
		if A[1] <= B[1] <= C[1] or A[1] >= B[1] >= C[1]:
			print('YES')
		else:
			print('NO')
	elif A[1] == B[1] == C[1] or A[1] == B[1] or B[1] == C[1]:
		if A[0] <= B[0] <= C[0] or A[0] >= B[0] >= C[0]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
for i in range(t):
	c = 0
	flag = False
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	if ya == yb:
		if xc >= xb and xb >= xa or (xa >= xb and xb >= xc):
			flag = True
	elif xb == xc:
		if ya >= yb and yb >= yc or (ya <= yb and yb <= yc):
			flag = True
	elif xb == xa:
		if ya >= yb and yb >= yc or (ya <= yb and yb <= yc):
			flag = True
	elif yb == yc:
		if xc >= xb and xb >= xa or (xa >= xb and xb >= xc):
			flag = True
	else:
		flag = False
	if flag == True:
		print('YES')
	else:
		print('NO')


for T in range(int(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] or A[0] == B[0] or B[0] == C[0]:
		if A[1] <= B[1] <= C[1] or A[1] >= B[1] >= C[1]:
			print('YES')
		else:
			print('NO')
	elif A[1] == B[1] == C[1] or A[1] == B[1] or B[1] == C[1]:
		if A[0] <= B[0] <= C[0] or A[0] >= B[0] >= C[0]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


test = int(input())
for i in range(0, test):
	(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 <= y3 or y1 >= y2 >= y3:
			print('YES')
		else:
			print('NO')
	elif y1 == y2 == y3:
		if x1 <= x2 <= x3 or x1 >= x2 >= x3:
			print('YES')
		else:
			print('NO')
	elif x2 == x3:
		if y2 == y3:
			print('YES')
		elif y2 > y3:
			if y1 >= y2:
				print('YES')
			else:
				print('NO')
		elif y3 > y2:
			if y1 <= y2:
				print('YES')
			else:
				print('NO')
	elif y2 == y3:
		if x2 == x3:
			print('YES')
		elif x2 > x3:
			if x1 >= x2:
				print('YES')
			else:
				print('NO')
		elif x3 > x2:
			if x1 <= x2:
				print('YES')
			else:
				print('NO')
	elif x1 == x2:
		if y1 <= y2 <= y3 or y1 >= y2 >= y3:
			print('YES')
		else:
			print('NO')
	elif y1 == y2:
		if x1 <= x2 <= x3 or x1 >= x2 >= x3:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


for i in range(int(input())):
	(ax, ay) = [int(i) for i in input().split()]
	(bx, by) = [int(i) for i in input().split()]
	(cx, cy) = [int(i) for i in input().split()]
	(s1_x, s1_y) = (ax, cy)
	(s2_x, s2_y) = (cx, ay)
	if s1_x == bx and by >= min([s1_y, ay]) and (by <= max([s1_y, ay])):
		print('YES')
	elif s1_y == by and bx >= min([s1_x, cx]) and (bx <= max([s1_x, cx])):
		print('YES')
	elif s2_x == bx and by >= min([s2_y, cy]) and (by <= max([s2_y, cy])):
		print('YES')
	elif s2_y == by and bx >= min([s2_x, ax]) and (bx <= max([s2_x, ax])):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(xa, ya) = map(int, input().split())
	(xb, yb) = map(int, input().split())
	(xc, yc) = map(int, input().split())
	if xb == xa and yb in range(min(ya, yc), max(ya, yc) + 1):
		print('YES')
	elif xb == xc and yb in range(min(ya, yc), max(ya, yc) + 1):
		print('YES')
	elif yb == ya and xb in range(min(xa, xc), max(xa, xc) + 1):
		print('YES')
	elif yb == yc and xb in range(min(xa, xc), max(xa, xc) + 1):
		print('YES')
	else:
		print('NO')


t = int(input(''))
for i in range(0, t):
	(x1, y1) = input('').split()
	(x2, y2) = input('').split()
	(x3, y3) = input('').split()
	x1 = int(x1)
	x2 = int(x2)
	x3 = int(x3)
	y1 = int(y1)
	y2 = int(y2)
	y3 = int(y3)
	if x1 == x2 or y1 == y2:
		if x1 == x2 and y1 <= y2 and (y3 >= y2):
			print('YES')
		elif x1 == x2 and y1 >= y2 and (y3 <= y2):
			print('YES')
		elif y1 == y2 and x1 <= x2 and (x3 >= x2):
			print('YES')
		elif y1 == y2 and x1 >= x2 and (x3 <= x2):
			print('YES')
		else:
			print('NO')
	elif x2 == x3 or y2 == y3:
		if x2 == x3 and y2 <= y3 and (y1 <= y2):
			print('YES')
		elif x2 == x3 and y2 >= y3 and (y1 >= y2):
			print('YES')
		elif y2 == y3 and x3 >= x2 and (x2 >= x1):
			print('YES')
		elif y2 == y3 and x3 <= x2 and (x1 >= x2):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')