You have a matrix $2 \times 2$ filled with distinct integers. You want your matrix to become beautiful. The matrix is beautiful if the following two conditions are satisfied:

in each row, the first element is smaller than the second element;

in each column, the first element is smaller than the second element.

You can perform the following operation on the matrix any number of times: rotate it clockwise by $90$ degrees, so the top left element shifts to the top right cell, the top right element shifts to the bottom right cell, and so on:

Determine if it is possible to make the matrix beautiful by applying zero or more operations.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

Each test case consists of two lines. Each of those lines contains two integers — the elements of the corresponding row of the matrix. In each matrix, all four elements are distinct integers from $1$ to $100$.


-----Output-----

For each test case, print YES if the matrix can become beautiful, or NO otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).


-----Examples-----

Input
6
1 3
5 7
8 10
3 4
8 10
4 3
6 1
9 2
7 5
4 2
1 2
4 3
Output
YES
YES
NO
YES
YES
NO


-----Note-----

None

Source: codeforces | Difficulty: EASY
Tags: Implementation

Complete search


Solutions:
t = int(input())
for tc in range(t):
	(a0, a1) = map(int, input().split(' '))
	(a2, a3) = map(int, input().split(' '))
	if a0 < a1 and a2 < a3 and (a0 < a2) and (a1 < a3):
		print('YES')
	elif a2 < a0 and a3 < a1 and (a2 < a3) and (a0 < a1):
		print('YES')
	elif a3 < a2 and a1 < a0 and (a3 < a1) and (a2 < a0):
		print('YES')
	elif a1 < a3 and a0 < a2 and (a1 < a0) and (a3 < a2):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())

	def pan(a, b, c, d):
		if a < b and c < d and (a < c) and (b < d):
			return True
		return False

	def func(a, b, c, d):
		return (c, a, d, b)
	bo = False
	for i in range(4):
		if pan(a, b, c, d):
			print('YES')
			bo = True
			break
		else:
			(a, b, c, d) = func(a, b, c, d)
	if not bo:
		print('NO')


def check(l):
	return l[0][0] < l[0][1] and l[1][0] < l[1][1] and (l[0][0] < l[1][0]) and (l[0][1] < l[1][1])
n = int(input())
for i in range(n):
	l = []
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = [a, b]
	if check(l):
		print('YES')
		continue
	tmp = l[0][0]
	l[0][0] = l[0][1]
	l[0][1] = l[1][1]
	l[1][1] = l[1][0]
	l[1][0] = tmp
	if check(l):
		print('YES')
		continue
	tmp = l[0][0]
	l[0][0] = l[0][1]
	l[0][1] = l[1][1]
	l[1][1] = l[1][0]
	l[1][0] = tmp
	if check(l):
		print('YES')
		continue
	tmp = l[0][0]
	l[0][0] = l[0][1]
	l[0][1] = l[1][1]
	l[1][1] = l[1][0]
	l[1][0] = tmp
	if check(l):
		print('YES')
		continue
	print('NO')


for _ in range(int(input())):
	a = [0 for _ in range(4)]
	(a[0], a[1]) = list(map(int, input().split()))
	(a[2], a[3]) = list(map(int, input().split()))
	flag = False
	if a[0] < a[1] and a[0] < a[2] and (a[1] < a[3]) and (a[2] < a[3]):
		flag = True
	if a[2] < a[0] and a[2] < a[3] and (a[0] < a[1]) and (a[3] < a[1]):
		flag = True
	if a[3] < a[2] and a[3] < a[1] and (a[2] < a[0]) and (a[1] < a[0]):
		flag = True
	if a[1] < a[3] and a[1] < a[0] and (a[3] < a[2]) and (a[0] < a[2]):
		flag = True
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
results = []
for i in range(t):
	s1 = list(map(int, input().strip().split()))
	s2 = list(map(int, input().strip().split()))
	if s1[0] < s1[1] and s2[0] < s2[1] and (s1[0] < s2[0]) and (s1[1] < s2[1]):
		results.append('YES')
	elif s1[0] > s1[1] and s2[0] > s2[1] and (s1[0] < s2[0]) and (s1[1] < s2[1]):
		results.append('YES')
	elif s1[0] > s1[1] and s2[0] > s2[1] and (s1[0] > s2[0]) and (s1[1] > s2[1]):
		results.append('YES')
	elif s1[0] < s1[1] and s2[0] < s2[1] and (s1[0] > s2[0]) and (s1[1] > s2[1]):
		results.append('YES')
	else:
		results.append('NO')
for j in results:
	print(j)


t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	(flug, i) = (True, 6)
	while i > 0:
		if a < b and a < c and (d > b) and (d > c):
			print('YES')
			flug = False
			break
		else:
			(a, b, c, d) = (c, a, d, b)
		i -= 1
	if flug:
		print('NO')


n = int(input())
for _ in range(n):
	r1 = map(int, input().split(' '))
	r2 = map(int, input().split(' '))
	pos = False
	for _ in range(4):
		(a, b) = r1
		(c, d) = r2
		r1 = [c, a]
		r2 = [d, b]
		if r1[0] < r1[1] and r2[0] < r2[1] and (r1[0] < r2[0]) and (r1[1] < r2[1]):
			print('YES')
			pos = True
			break
	if not pos:
		print('NO')


t = int(input())
for i in range(t):
	ans = 'NO'
	(a1, a2) = map(int, input().split())
	(a3, a4) = map(int, input().split())
	for j in range(4):
		if a1 < a2 and a3 < a4 and (a1 < a3) and (a2 < a4):
			ans = 'YES'
			break
		(a1, a2, a3, a4) = (a3, a1, a4, a2)
	print(ans)


def check(m):
	if m[0][0] < m[1][0] < m[1][1] and m[0][0] < m[0][1] < m[1][1]:
		return True
	else:
		return False

def rotate(m):
	t = [[0, 0], [0, 0]]
	t[0][0] = m[1][0]
	t[0][1] = m[0][0]
	t[1][1] = m[0][1]
	t[1][0] = m[1][1]
	return t
for _ in range(int(input())):
	m = [[int(x) for x in input().split()], [int(x) for x in input().split()]]
	if m[0][0] < m[1][0] < m[1][1] and m[0][0] < m[0][1] < m[1][1]:
		print('YES')
	else:
		m = rotate(m)
		if check(m):
			print('YES')
		else:
			m = rotate(m)
			if check(m):
				print('YES')
			else:
				m = rotate(m)
				if check(m):
					print('YES')
				else:
					print('NO')


def abc(a, b):
	x1 = True
	x2 = True
	x3 = True
	x4 = True
	if a[0] > a[1]:
		x1 = False
	if b[0] > b[1]:
		x2 = False
	if a[0] > b[0]:
		x3 = False
	if a[1] > b[1]:
		x4 = False
	if x1 == False and x2 == False and (x3 == False) and (x4 == False) or (x1 != False and x2 != False and (x3 != False) and (x4 != False)) or (x1 == True and x2 == True and (x3 == False) and (x4 == False)) or (x1 == False and x2 == False and (x3 == True) and (x4 == True)):
		return True
	else:
		return False
for _ in range(int(input())):
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	a = abc(x, y)
	if a == True:
		print('YES')
	else:
		print('NO')


def diag(a, b, c, d):
	if a == max(a, b, c, d) and d == min(a, b, c, d):
		return 'YES'
	if d == max(a, b, c, d) and a == min(a, b, c, d):
		return 'YES'
	if b == max(a, b, c, d) and c == min(a, b, c, d):
		return 'YES'
	if c == max(a, b, c, d) and b == min(a, b, c, d):
		return 'YES'
	return 'NO'
t = int(input())
for iter in range(t):
	(a, b) = list(map(int, input().split()))
	(c, d) = list(map(int, input().split()))
	print(diag(a, b, c, d))


t = int(input())
for pushups in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	A = [a, b, d, c]
	x = max(A)
	y = min(A)
	if abs(A.index(x) - A.index(y)) == 2:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	lst = [a, b, c, d, a, b]
	if abs(lst.index(min(lst)) - lst.index(max(lst))) == 3:
		print('YES')
	else:
		lst.pop(0)
		lst.pop(0)
		if abs(lst.index(min(lst)) - lst.index(max(lst))) == 3:
			print('YES')
		else:
			print('NO')


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	(c, d) = list(map(int, input().split()))
	if a < b and c < d and (a < c) and (b < d):
		print('YES')
	elif a < b and c < d and (a > c) and (b > d):
		print('YES')
	elif a > b and c > d and (a < c) and (b < d):
		print('YES')
	elif a > b and c > d and (a > c) and (b > d):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b) = input().split()
	(c, d) = input().split()
	if int(a) > int(b) and int(c) > int(d):
		if int(a) > int(c) and int(b) > int(d):
			print('YES')
		elif int(a) < int(c) and int(b) < int(d):
			print('YES')
		else:
			print('NO')
	elif int(a) < int(b) and int(c) < int(d):
		if int(a) > int(c) and int(b) > int(d):
			print('YES')
		elif int(a) < int(c) and int(b) < int(d):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input(''))
A = []
B = []
C = []
for i in range(t):
	p = [int(z) for z in input('').split()]
	q = [int(z) for z in input('').split()]
	r = [p[0], p[1], q[0], q[1]]
	r.sort()
	x = [p[0], q[1]]
	x.sort()
	y = [p[1], q[0]]
	y.sort()
	A.append(x)
	B.append(y)
	C.append([r[0], r[3]])
for i in range(t):
	arr1 = A[i]
	arr2 = B[i]
	arr3 = C[i]
	if arr1 == arr3 or arr2 == arr3:
		print('YES')
	else:
		print('NO')


def rotatemat(mat):
	(mat[1][0], mat[0][1]) = (mat[0][1], mat[1][0])
	mat[0] = mat[0][::-1]
	mat[1] = mat[1][::-1]
	return mat

def rotate(nums):
	for mat in nums:
		for _ in range(4):
			if mat[0][0] < mat[0][1] and mat[0][0] < mat[1][0] and (mat[0][1] < mat[1][1]) and (mat[1][0] < mat[1][1]):
				print('YES')
				break
			mat = rotatemat(mat)
		else:
			print('NO')
n = int(input())
nums = []
for i in range(n):
	mat = []
	l1 = [int(el) for el in input().split()]
	l2 = [int(el) for el in input().split()]
	nums.append([l1, l2])
rotate(nums)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	e = [a, b, d, c]
	ind = e.index(min(e))
	f = 0
	if ind == 0:
		if e[0] < e[1] and e[1] < e[2] and (e[2] > e[3]):
			print('YES')
		else:
			print('NO')
	elif ind == 1:
		if e[1] < e[2] and e[2] < e[3] and (e[3] > e[0]):
			print('YES')
		else:
			print('NO')
	elif ind == 2:
		if e[2] < e[3] and e[3] < e[0] and (e[0] > e[1]):
			print('YES')
		else:
			print('NO')
	elif ind == 3:
		if e[3] < e[0] and e[0] < e[1] and (e[1] > e[2]):
			print('YES')
		else:
			print('NO')


for i in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	l = []
	for i in range(4):
		f = a
		a = b
		b = d
		d = c
		c = f
		if a < b < c < d or a < c < b < d:
			l.append('YES')
		else:
			l.append('NO')
	if 'YES' in l:
		print('YES')
	else:
		print('NO')


n = int(input(''))
j = 0
while j != n:
	wartosc = 0
	elo = input('')
	elo2 = input('')
	for i in range(len(elo)):
		if elo[i] == ' ':
			tl = int(elo[0:i])
			tp = int(elo[i + 1:])
			break
	for i in range(len(elo2)):
		if elo2[i] == ' ':
			bl = int(elo2[0:i])
			bp = int(elo2[i + 1:])
			break
	if tl < tp and bl < bp and (tl < bl) and (tp < bp):
		print('YES')
		wartosc += 1
	else:
		for i in range(3):
			tmp = tl
			tl = bl
			bl = bp
			bp = tp
			tp = tmp
			if tl < tp and bl < bp and (tl < bl) and (tp < bp):
				print('YES')
				wartosc += 1
				break
	if wartosc == 0:
		print('NO')
	j += 1


i = int(input())
g = []
for y in range(i):
	(u, u1) = map(int, input().split())
	(t, t1) = map(int, input().split())
	if u < u1 and u < t and (u1 < t1) and (t < t1):
		g.append('YES')
	elif t < u and t < t1 and (t1 < u1) and (u < u1):
		g.append('YES')
	elif t1 < t and t1 < u1 and (u1 < u) and (t < u):
		g.append('YES')
	elif u1 < t1 and u1 < u and (u < t) and (t1 < t):
		g.append('YES')
	else:
		g.append('NO')
[print(uu) for uu in g]


for _ in range(int(input())):
	m = [list(map(int, input().split())) for x in range(2)]
	f = 0
	for x in range(4):
		if m[0][0] < m[0][1] and m[1][0] < m[1][1] and (m[0][0] < m[1][0]) and (m[0][1] < m[1][1]):
			f = 1
			break
		(m[0][0], m[0][1], m[1][1], m[1][0]) = (m[0][1], m[1][1], m[1][0], m[0][0])
	if f == 1:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	answ = True
	for i in range(4):
		if a < b and a < c and (c < d) and (b < d):
			answ = True
			print('YES')
			break
		else:
			(a, b, c, d) = (b, d, a, c)
			answ = False
	if not answ:
		print('NO')


a = int(input())
for i in range(a):
	b = input()
	c = input()
	(num1, num2, num3, num4) = (0, 0, 0, 0)
	for i in b:
		if i == ' ':
			num1 = int(b[:b.index(i)])
			num2 = int(b[b.index(i) + 1:])
			break
	for i in c:
		if i == ' ':
			num3 = int(c[:c.index(i)])
			num4 = int(c[c.index(i) + 1:])
			break
	z = 1
	for i in range(4):
		if num1 < num2 and num3 < num4 and (num1 < num3) and (num2 < num4):
			print('YES')
			z = 0
			break
		else:
			temp = num1
			num1 = num3
			num3 = num4
			num4 = num2
			num2 = temp
	if z == 1:
		print('NO')


for t in range(int(input())):
	f = [int(x) for x in input('').split(' ')]
	s = [int(x) for x in input('').split(' ')]
	k = 0
	for i in range(4):
		if f[0] < f[1] and s[0] < s[1]:
			if f[0] < s[0] and f[1] < s[1]:
				k = 1
		(f[0], f[1], s[0], s[1]) = (s[0], f[0], s[1], f[1])
	if k:
		print('YES')
	else:
		print('NO')


t = int(input())

def f(a, b, c, d):
	if (min(a, b, c, d), max(a, b, c, d)) == (a, d) or (min(a, b, c, d), max(a, b, c, d)) == (d, a) or (min(a, b, c, d), max(a, b, c, d)) == (b, c) or ((min(a, b, c, d), max(a, b, c, d)) == (c, b)):
		return 'YES'
	else:
		return 'NO'
answers = []
for k in range(t):
	a_b = input()
	c_d = input()
	[a, b] = a_b.split()
	[c, d] = c_d.split()
	answers.append(f(int(a), int(b), int(c), int(d)))
for k in range(t):
	print(answers[k])


for _ in range(int(input())):
	out = 'NO'
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	for i in range(4):
		if c > a < b and c < d > b:
			out = 'YES'
			break
		else:
			(a, b, c, d) = (c, a, d, b)
	print(out)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	if a < b and c < d and (a < c) and (b < d):
		print('YES')
	else:
		f = False
		for i in range(4):
			if a < b and c < d and (a < c) and (b < d):
				f = True
				break
			ta = a
			tb = b
			td = d
			a = c
			b = ta
			d = tb
			c = td
		if f:
			print('YES')
		else:
			print('NO')


t = int(input())

def beautiful(a, b, x, y):
	if a < b and x < y and (a < x) and (b < y):
		return True
	else:
		return False
for i in range(t):
	r1 = input().split(' ')
	r2 = input().split(' ')
	a = int(r1[0])
	b = int(r1[1])
	x = int(r2[0])
	y = int(r2[1])
	if beautiful(a, b, x, y):
		print('YES')
	elif beautiful(x, a, y, b):
		print('YES')
	elif beautiful(y, x, b, a):
		print('YES')
	elif beautiful(b, y, a, x):
		print('YES')
	else:
		print('NO')


def beaitiful_matrix(matrix):
	if matrix[0][0] < matrix[0][1] < matrix[1][1] and matrix[0][0] < matrix[1][0] < matrix[1][1]:
		return True
for i in range(int(input())):
	flag = True
	matrix1 = list(map(int, input().split()))
	matrix2 = list(map(int, input().split()))
	matrix = [matrix1, matrix2]
	for g in range(4):
		if beaitiful_matrix(matrix):
			flag = False
			print('YES')
			break
		else:
			matrix3 = [elem.copy() for elem in matrix]
			matrix3[0][0] = matrix[1][0]
			matrix3[0][1] = matrix[0][0]
			matrix3[1][1] = matrix[0][1]
			matrix3[1][0] = matrix[1][1]
			matrix = matrix3
	if flag:
		print('NO')


from sys import stdin

def rotate(matrix):
	aux = [[0, 0], [0, 0]]
	aux[0][0] = matrix[1][0]
	aux[0][1] = matrix[0][0]
	aux[1][0] = matrix[1][1]
	aux[1][1] = matrix[0][1]
	return aux

def solve(matrix, cont=0):
	if cont < 4:
		if matrix[0][0] < matrix[0][1] and matrix[0][0] < matrix[1][0] and (matrix[0][1] < matrix[1][1]) and (matrix[1][0] < matrix[1][1]):
			return 'YES'
		return solve(rotate(matrix), cont + 1)
	return 'NO'

def main():
	for _ in range(int(stdin.readline().strip())):
		matrix = []
		for _ in range(2):
			matrix.append(list(map(int, stdin.readline().strip().split())))
		print(solve(matrix))
main()


for _ in range(int(input())):
	ans = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
	max_val = float('INF')
	min_val = 0
	(a, b) = [int(x) for x in input().split()]
	(c, d) = [int(x) for x in input().split()]
	lst = [a, b, c, d]
	max_val = min(max_val, min(lst))
	min_val = max(min_val, max(lst))
	if a == max_val and d == min_val or (a == min_val and d == max_val):
		print('YES')
	elif b == max_val and c == min_val or (b == min_val and c == max_val):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
inp = sys.stdin.readline

def input():
	return inp().strip()

def ii():
	return int(input())

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

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

def solve():
	(a, b) = mi()
	(c, d) = mi()
	for _ in range(4):
		if a < d and a < c and (a < b) and (d > max(b, c)):
			print('YES')
			return
		(a, b, c, d) = (c, a, d, b)
	print('NO')

def main():
	for _ in range(ii()):
		solve()
main()


def helper(mat):
	dir = [(0, 1), (1, 0), (-1, 0), (0, -1)]
	ans = [[0, 0], [0, 0]]
	c = 0
	for i in range(len(mat)):
		for j in range(len(mat[0])):
			ans[i + dir[c][0]][j + dir[c][1]] = mat[i][j]
			c += 1
	return ans

def checker(mat):
	for i in range(2):
		if mat[i][0] >= mat[i][1]:
			return False
		if mat[0][i] >= mat[1][i]:
			return False
	return True
for i in range(int(input())):
	mat = []
	mat.append(list(map(int, input().split(' '))))
	mat.append(list(map(int, input().split(' '))))
	y = False
	for j in range(4):
		if checker(mat):
			y = True
			print('YES')
			break
		else:
			mat = helper(mat)
	if not y:
		print('NO')


t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	ok = False
	for i in range(4):
		if a < b and c < d and (a < c) and (b < d):
			ok = True
		(a, b, c, d) = (b, d, a, c)
	if ok:
		print('YES')
	else:
		print('NO')
	t -= 1


def solve(a, b, c, d):
	d1 = {}
	mi = min(a, b, c, d)
	ma = max(a, b, c, d)
	d1[a] = 1
	d1[b] = 2
	d1[c] = 2
	d1[d] = 1
	if d1[mi] == d1[ma]:
		return 'YES'
	return 'NO'
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	print(solve(a, b, c, d))


import sys

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

def in_str():
	return sys.stdin.readline().rstrip()

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

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

def in_arr_str():
	return sys.stdin.readline().split()

def is_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			return True
	return False

def check(arr):
	if arr[0][0] < arr[0][1] < arr[1][1] and arr[0][0] < arr[1][0] < arr[1][1]:
		return True
	return False

def solve(arr):
	for _ in range(4):
		if check(arr):
			return 'YES'
		(arr[0][1], arr[1][1], arr[1][0], arr[0][0]) = (arr[0][0], arr[0][1], arr[1][1], arr[1][0])
	return 'NO'

def main():
	t = in_int()
	for _ in range(t):
		arr = [[0 for _ in range(2)] for _ in range(2)]
		arr[0] = list(map(int, in_str().split()))
		arr[1] = list(map(int, in_str().split()))
		print(solve(arr))
main()


n = int(input())
res = []

def check(a, b, c, d):
	if a > b and a > c and (d < c) and (d < b) or (a < b and b > d and (c < d) and (c < a)) or (c > a and c > d and (b < a) and (b < d)) or (d > c and d > b and (a < c) and (a < b)):
		return True
	else:
		return False
for i in range(n):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	if check(a, b, c, d):
		res.append('YES')
	else:
		res.append('NO')
for i in res:
	print(i)


def gs():
	return input()

def gi():
	return int(input())

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

def gt():
	return map(int, input().split())
t = gi()
for _ in range(t):
	(a, b) = gt()
	(c, d) = gt()
	if a < c and a < b and (d > c) and (d > b):
		print('YES')
	elif c < a and c < d and (b > a) and (b > d):
		print('YES')
	elif b < a and b < d and (c > a) and (c > d):
		print('YES')
	elif d < b and d < c and (a > c) and (a > b):
		print('YES')
	else:
		print('NO')


def checking(exp):
	if (exp[0][0] < exp[0][1] and exp[1][0] < exp[1][1]) and (exp[0][0] < exp[1][0] and exp[0][1] < exp[1][1]):
		return True
	else:
		return False

def rotate(a):
	result = []
	for i in range(2):
		temp_result = []
		for k in reversed(range(2)):
			temp_result.append(a[k][i])
		result.append(temp_result)
	return result

def processing(exp):
	if checking(exp):
		return 'YES'
	else:
		i = 4
		while i >= 1:
			temp_list = rotate(exp)
			if checking(temp_list):
				return 'YES'
			else:
				i -= 1
				exp = temp_list
		return 'NO'
t = int(input())
while t > 0:
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	print(processing([a, b]))
	t -= 1


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	p1 = a > b and a > c and (c > d) and (b > d)
	p2 = c > d and c > a and (a > b) and (d > b)
	p3 = d > c and d > b and (c > a) and (b > a)
	p4 = b > a and b > d and (a > c) and (d > c)
	if p1 or p2 or p3 or p4:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	if min(b, c) > min(a, d) and max(b, c) < max(a, d) or (min(a, d) > min(b, c) and max(a, d) < max(b, c)):
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s.strip())

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(a, b) = invr()
	(c, d) = invr()
	arr = [a, b, d, c]
	for i in range(4):
		temp = arr[i:] + arr[0:i]
		if temp[0] <= temp[1] and temp[0] <= temp[3] and (temp[1] <= temp[2]) and (temp[3] <= temp[2]):
			print('YES')
			break
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	(c, d) = list(map(int, input().split()))
	for r in range(4):
		if a < b < d and a < c < d:
			print('YES')
			break
		(a, b, d, c) = (c, a, b, d)
	else:
		print('NO')


answer = []
n = int(input())

def partition(arr):
	new_arr = [0] * 4
	(new_arr[0], new_arr[1], new_arr[2], new_arr[3]) = (arr[2], arr[0], arr[3], arr[1])
	return new_arr
for _ in range(n):
	(a1, a2) = [int(i) for i in input().split()]
	(b1, b2) = [int(i) for i in input().split()]
	arr = [a1, a2, b1, b2]
	flag = False
	for i in range(4):
		if arr[0] <= arr[1] <= arr[3] and arr[0] <= arr[2] <= arr[3]:
			answer.append('YES')
			flag = True
			break
		arr = partition(arr)
	if flag == False:
		answer.append('NO')
for el in answer:
	print(el)


for _ in range(int(input())):
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	c = 0
	while 1:
		if a[0] < a[1] < b[1] and a[0] < b[0] < b[1]:
			print('YES')
			break
		if c == 4:
			print('NO')
			break
		else:
			t = a[1]
			(a[1], a[0]) = (a[0], b[0])
			(b[0], b[1]) = (b[1], t)
			c += 1


num = int(input())
for i in range(0, num):
	flag = 0
	(a, b) = map(int, input().split(' '))
	(c, d) = map(int, input().split(' '))
	l = [a, b, c, d]
	l2 = []
	for i in range(0, 4):
		l2 = []
		if l[0] < l[1] and l[0] < l[2] and (l[2] < l[3]) and (l[1] < l[3]):
			flag = 1
			break
		l2.append(l[2])
		l2.append(l[0])
		l2.append(l[3])
		l2.append(l[1])
		l = l2.copy()
	if flag == 1:
		print('YES')
	else:
		print('NO')


n = int(input())

def check(k1, k2):
	if k1[0] < k1[1] and k1[0] < k2[0] and (k2[0] < k2[1]) and (k1[1] < k2[1]):
		return True
	return False
for i in range(n):
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	if check(a1, a2):
		print('YES')
		continue
	elif check([a2[0], a1[0]], [a2[1], a1[1]]):
		print('YES')
		continue
	elif check([a2[1], a2[0]], [a1[1], a1[0]]):
		print('YES')
		continue
	elif check([a1[1], a2[1]], [a1[0], a2[0]]):
		print('YES')
		continue
	else:
		print('NO')


n = int(input())
for i in range(n):
	a = []
	b = [int(s) for s in input().split()]
	c = [int(s) for s in input().split()]
	a += b
	a += c
	if a.index(max(a)) + a.index(min(a)) == 3:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	if max(a, b, c, d) - min(a, b, c, d) == abs(a - d) or max(a, b, c, d) - min(a, b, c, d) == abs(b - c):
		print('YES')
	else:
		print('NO')


def is_beautiful(a):
	if a[0] < a[1] and a[2] < a[3] and (a[0] < a[2]) and (a[1] < a[3]):
		return True
	return False
t = int(input())
for _ in range(t):
	matrix = list(map(int, input().split() + input().split()))
	matrix_beauty = is_beautiful(matrix)
	i = 0
	while not matrix_beauty and i < 3:
		(matrix[0], matrix[1], matrix[2], matrix[3]) = (matrix[2], matrix[0], matrix[3], matrix[1])
		matrix_beauty = is_beautiful(matrix)
		i += 1
	print('YES' if matrix_beauty else 'NO')


tc = int(input())
for _ in range(tc):
	r1 = input().split()
	r1 = [int(x) for x in r1]
	r2 = input().split()
	r2 = [int(x) for x in r2]
	r = [r1, r2]
	rnd = 0
	while rnd < 4:
		if r[0][0] < r[0][1] and r[1][0] < r[1][1] and (r[0][0] < r[1][0]) and (r[0][1] < r[1][1]):
			print('YES')
			rnd = 0
			break
		else:
			a = r[1][0]
			b = r[0][0]
			c = r[1][1]
			d = r[0][1]
			r[0][0] = a
			r[0][1] = b
			r[1][0] = c
			r[1][1] = d
			rnd += 1
		if rnd == 4:
			print('NO')


def beauty_checker(arr):
	if arr.index(max(arr)) + arr.index(min(arr)) == 3:
		return 'YES'
	else:
		return 'NO'

def matrix_to_arr(str1, str2):
	arr = []
	for i in range(2):
		arr.append(int(str1.split(' ')[i]))
	for i in range(2):
		arr.append(int(str2.split(' ')[i]))
	return arr
t = int(input())
arr = []
answers = []
for i in range(t):
	arr = matrix_to_arr(str(input()), str(input()))
	answers.append(beauty_checker(arr))
for i in range(t):
	print(answers[i])


number_of_tests = int(input())
for test in range(number_of_tests):
	matrix = []
	for i in range(2):
		for number in input().split(' '):
			matrix.append(int(number))
	if (matrix[0] < matrix[1]) == (matrix[2] < matrix[3]) and (matrix[0] < matrix[2]) == (matrix[1] < matrix[3]):
		print('YES')
	else:
		print('NO')


for i in [list(map(int, input().split() + input().split())) for j in range(int(input()))]:
	print(['NO', 'YES'][i.index(max(i)) + i.index(min(i)) == 3])


n = input()
for i in range(int(n)):
	inp = input()
	(a, b) = list(map(int, inp.split()))
	inp = input()
	(c, d) = list(map(int, inp.split()))
	if a < b and a < c and (d > c) and (d > b):
		print('YES')
	elif b < a and b < d and (c > a) and (c > d):
		print('YES')
	elif c < a and c < d and (b > a) and (b > d):
		print('YES')
	elif d < b and d < c and (a > c) and (a > b):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	a = list(map(int, input().split())) + list(map(int, input().split()))
	(c, d) = (a.index(max(a)), a.index(min(a)))
	if c + d == 3:
		print('YES')
	else:
		print('NO')


a = int(input())
for i in range(a):
	(c, c1) = input().split()
	(d, d1) = input().split()
	(d, d1) = (int(d), int(d1))
	(c, c1) = (int(c), int(c1))
	if c < c1 and c < d and (c1 < d1) and (d < d1):
		print('YES')
	elif d < c and d1 < c1 and (d < d1) and (c < c1):
		print('YES')
	elif d1 < d and c1 < c and (d1 < c1) and (d < c):
		print('YES')
	elif c1 < d1 and c < d and (c1 < c) and (d1 < d):
		print('YES')
	else:
		print('NO')


n = int(input())

def rot(a, b, c, d):
	temp = a
	a = c
	c = d
	d = b
	b = temp
	return (a, b, c, d)
for val in range(n):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	flag = 0
	for t in range(4):
		if a < b and c < d and (a < c) and (b < d):
			print('YES')
			flag = 1
			break
		else:
			(a, b, c, d) = rot(a, b, c, d)
	if not flag:
		print('NO')


def is_beautiful(nums):
	for _ in range(4):
		if nums[0][0] < nums[0][1] and nums[0][0] < nums[1][0] and (nums[1][0] < nums[1][1]) and (nums[0][1] < nums[1][1]):
			return 'YES'
		(nums[0][0], nums[0][1], nums[1][0], nums[1][1]) = (nums[1][0], nums[0][0], nums[1][1], nums[0][1])
	return 'NO'
for _ in range(int(input())):
	nums = [[int(x) for x in input().split()] for _ in range(2)]
	result = is_beautiful(nums)
	print(result)


def check(matrix):
	m = matrix
	for _ in range(4):
		(m[3], m[2], m[0], m[1]) = (m[1], m[3], m[2], m[0])
		if m[0] < m[1] and m[0] < m[2] and (m[1] < m[3]) and (m[2] < m[3]):
			return True
	return False
for t in range(int(input())):
	n = []
	for _ in range(2):
		n += list(map(int, input().split()))
	print('YES' if check(n) else 'NO')


for t in range(int(input())):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	print('YES' if (a - b) * (c - d) > 0 and (a - c) * (b - d) > 0 else 'NO')


answers = []
for i in range(int(input())):
	(a, b) = map(int, input().split(' '))
	(c, d) = map(int, input().split(' '))
	is_true = False
	for j in range(4):
		if a < b and c < d and (a < c) and (b < d):
			is_true = True
			break
		else:
			(a, b, c, d) = (c, a, d, b)
	if is_true:
		answers.append('YES')
	else:
		answers.append('NO')
for answer in answers:
	print(answer)


n = int(input())
for _ in range(n):
	l = []
	for i in range(2):
		l.append(list(map(int, input().split())))
	a = l[0][0]
	b = l[0][1]
	c = l[1][0]
	d = l[1][1]
	if a < b and a < c and (b < d) and (c < d):
		print('YES')
	elif c < a and d < b and (c < d) and (a < b):
		print('YES')
	elif d < c and d < b and (c < a) and (b < a):
		print('YES')
	elif b < d and a < c and (b < a) and (d < c):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	arr = [[a, b], [c, d]]
	for i in range(4):
		if arr[0][0] > arr[0][1] and arr[0][0] > arr[1][0] and (arr[0][0] > arr[1][1]) and (arr[0][1] > arr[1][1]) and (arr[1][0] > arr[1][1]):
			print('YES')
			break
		(arr[0][0], arr[0][1], arr[1][0], arr[1][1]) = (arr[1][0], arr[0][0], arr[1][1], arr[0][1])
	else:
		print('NO')


t = int(input())
for i in range(t):
	(A, B) = map(int, input().split())
	(C, D) = map(int, input().split())
	answer = 'NO'
	for i in range(4):
		if A == min(A, B, C, D) and D == max(A, B, C, D):
			answer = 'YES'
		(A, B, C, D) = (B, D, A, C)
	print(answer)


t = int(input())
for i in range(t):
	a = [0, 0]
	a[0] = list(map(int, input().split()))
	a[1] = list(map(int, input().split()))
	b = a[0][:]
	b.extend(a[1])
	res = 'NO'
	for j in range(4):
		if b[1] > b[0] and b[2] > b[0] and (b[3] > b[1]) and (b[3] > b[2]):
			res = 'YES'
		(b[0], b[1], b[2], b[3]) = (b[2], b[0], b[3], b[1])
	print(res)


t = int(input())
for t_ in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	l = [a, b, d, c]
	poss = False
	for i in range(4):
		l = l[1:] + [l[0]]
		poss |= l[0] < l[1] and l[0] < l[3] and (l[1] < l[2]) and (l[3] < l[2])
	if poss:
		print('YES')
	else:
		print('NO')


import sys, math, heapq, bisect, random, itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)
ints = lambda : list(map(int, input().split()))
p = 10 ** 9 + 7
inf = 10 ** 20 + 7
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for t in range(int(input())):
	(a, b) = ints()
	(c, d) = ints()
	ans = 'NO'
	if a < b and c < d and (a < c) and (b < d):
		ans = 'YES'
	(a, b, c, d) = (b, d, a, c)
	if a < b and c < d and (a < c) and (b < d):
		ans = 'YES'
	(a, b, c, d) = (b, d, a, c)
	if a < b and c < d and (a < c) and (b < d):
		ans = 'YES'
	(a, b, c, d) = (b, d, a, c)
	if a < b and c < d and (a < c) and (b < d):
		ans = 'YES'
	(a, b, c, d) = (b, d, a, c)
	if a < b and c < d and (a < c) and (b < d):
		ans = 'YES'
	print(ans)


import sys
for i in range(int(sys.stdin.readline())):
	(a, b) = map(int, sys.stdin.readline().split())
	(c, d) = map(int, sys.stdin.readline().split())
	if a < b and c < d and (a < c) and (b < d):
		print('YES')
		continue
	if c < a and d < b and (c < d) and (a < b):
		print('YES')
		continue
	if d < b and d < c and (c < a) and (b < a):
		print('YES')
		continue
	if b < a and b < d and (d < c) and (a < c):
		print('YES')
		continue
	print('NO')


t = int(input())
for i in range(t):
	(f, s) = [int(i) for i in input().split()]
	(r, d) = [int(i) for i in input().split()]
	c = 0
	for j in range(4):
		if f < s and s < d and (r < d) and (f < r):
			c = 1
		tt = f
		f = s
		s = d
		d = r
		r = tt
	if c:
		print('YES')
	else:
		print('NO')


def check(a, b, c, d):
	if a < b and c < d and (a < c) and (b < d):
		return 0
	else:
		return 1
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(c, d) = map(int, input().split())
	v = 0
	if check(a, b, c, d) == 0:
		v = v + 1
	if check(c, a, d, b) == 0:
		v = v + 1
	if check(d, c, b, a) == 0:
		v = v + 1
	if check(b, d, a, c) == 0:
		v = v + 1
	if v == 0:
		print('NO')
	else:
		print('YES')


def Check(a, b, c, d):
	if a < b and a < d and (b < c) and (d < c):
		return True
	return False
t = int(input())
for _ in range(t):
	(a, b) = [int(i) for i in input().strip().split()]
	(d, c) = [int(i) for i in input().strip().split()]
	check = False
	for i in range(4):
		if Check(a, b, c, d):
			check = True
			break
		(a, b, c, d) = (d, a, b, c)
	if check:
		print('YES')
	else:
		print('NO')


def main():
	tc = int(input())
	for i in range(tc):
		m = []
		(a, b) = map(int, input().split())
		(d, c) = map(int, input().split())
		if a <= b and d <= c and (a <= d) and (b <= c):
			print('YES')
		elif d <= a and c <= b and (d <= c) and (a <= b):
			print('YES')
		elif c <= d and b <= a and (c <= b) and (d <= a):
			print('YES')
		elif b <= c and a <= d and (b <= a) and (c <= d):
			print('YES')
		else:
			print('NO')
main()


n = int(input())
for i in range(n):
	(m, l) = map(int, input().split())
	(j, k) = map(int, input().split())
	if m < l and j < k and (m < j) and (l < k):
		print('YES')
	elif j < m and m < l and (j < k) and (k < l):
		print('YES')
	elif k < l and k < j and (j < m) and (l < m):
		print('YES')
	elif l < m and l < k and (m < j) and (k < j):
		print('YES')
	else:
		print('NO')