You are given $\textit{q}$ queries where each query consists of a set of $n$ points on a two-dimensional plane (i.e., $(x,y)$). For each set of points, print YES on a new line if all the points fall on the edges (i.e., sides and/or corners) of a non-degenerate rectangle which is axis parallel; otherwise, print NO instead. 

Input Format

The first line contains a single positive integer, $\textit{q}$, denoting the number of queries. The subsequent lines describe each query in the following format:

The first line contains a single positive integer, $n$, denoting the number of points in the query.      
Each line $\boldsymbol{i}$ of the $n$ subsequent lines contains two space-separated integers describing the respective values of $x_i$ and $y_i$ for the point at coordinate $(x_i,y_i)$.

Constraints

$1\leq q\leq10$
$1\leq n\leq10$
$-10^4\leq x,y\leq10^4$

Output Format

For each query, print YES on a new line if all $n$ points lie on the edges of some non-degenerate rectangle which is axis parallel; otherwise, print NO instead. 

Sample Input
2
3
0 0
0 1
1 0
4
0 0
0 2
2 0
1 1

Sample Output
YES
NO

Explanation

We perform the following $q=2$ queries:

In the first query, all points lie on the edges of a non-degenerate rectangle with corners at $(0,0)$, $(0,1)$, $(1,0)$, and $(1,1)$. Thus, we print YES on a new line.
In the second query, points $(0,0)$, $(0,2)$, and $(2,0)$ could all lie along the edge of some non-degenerate rectangle, but point $(1,1)$ would have to fall inside that rectangle. Thus, we print NO on a new line.

Source: hackerrank | Difficulty: EASY
Tags: Geometry


Solutions:
def main():
	for i in range(int(input())):
		p = [list(map(int, input().split())) for j in range(int(input()))]
		(px, py) = zip(*p)
		x0 = min(px)
		x1 = max(px)
		y0 = min(py)
		y1 = max(py)
		result = all((x in (x0, x1) or y in (y0, y1) for (x, y) in p))
		print('YES' if result else 'NO')
main()


from fileinput import input
data = input()
for _ in range(int(next(data))):
	n = int(next(data))
	points = []
	for i in range(n):
		(x, y) = map(int, next(data).split())
		points.append((x, y))
	min_x = min([x for (x, y) in points])
	max_x = max([x for (x, y) in points])
	min_y = min([y for (x, y) in points])
	max_y = max([y for (x, y) in points])
	valid = True
	for (x, y) in points:
		edges = [min_x, min_y, max_x, max_y]
		if x not in edges and y not in edges:
			valid = False
			break
	if valid:
		print('YES')
	else:
		print('NO')


import sys
data = sys.stdin.readlines()
nbcs = int(data[0].strip())
l = 1
for i in range(1, nbcs + 1):
	lines = int(data[l].strip())
	tab1 = []
	tab2 = []
	l += 1
	for j in range(1, lines + 1):
		tab1.append(int(data[l].strip().split()[0]))
		tab2.append(int(data[l].strip().split()[1]))
		l += 1
	(min1, max1) = (tab1[0], tab1[0])
	(min2, max2) = (tab2[0], tab2[0])
	for j in range(0, lines):
		if tab1[j] > max1:
			max1 = tab1[j]
		if tab2[j] > max2:
			max2 = tab2[j]
		if tab1[j] < min1:
			min1 = tab1[j]
		if tab2[j] < min2:
			min2 = tab2[j]
	tt = True
	for j in range(0, lines):
		if (tab1[j] != min1 and tab1[j] != max1) and (tab2[j] != min2 and tab2[j] != max2):
			tt = False
			break
	if tt:
		print('YES')
	else:
		print('NO')


q = int(input())
for query in range(q):
	n = int(input())
	points = list()
	(max_x, max_y) = (-99999, -99999)
	(min_x, min_y) = (99999, 99999)
	for point in range(n):
		(x, y) = map(int, input().split())
		points.append((x, y))
		if x > max_x:
			max_x = x
		if x < min_x:
			min_x = x
		if y > max_y:
			max_y = y
		if y < min_y:
			min_y = y
	on_rectangle = True
	for point in points:
		if point[0] in (max_x, min_x):
			pass
		elif point[1] in (max_y, min_y):
			pass
		else:
			on_rectangle = False
			break
	if on_rectangle:
		print('YES')
	else:
		print('NO')


for _q in range(int(input().strip())):
	points = [tuple(map(int, input().strip().split())) for _ in range(int(input().strip()))]
	x0 = min([point[0] for point in points])
	x1 = max([point[0] for point in points])
	y0 = min([point[1] for point in points])
	y1 = max([point[1] for point in points])
	if all([point[0] == x0 or point[0] == x1 or point[1] == y0 or (point[1] == y1) for point in points]):
		print('YES')
	else:
		print('NO')


for q in range(int(input())):
	n = int(input())
	ptos = []
	esquinas = None
	for i in range(n):
		ptos.append([int(x) for x in input().split()])
		if esquinas == None:
			esquinas = [list(ptos[-1]), list(ptos[-1])]
		else:
			esquinas[0][0] = min(esquinas[0][0], ptos[-1][0])
			esquinas[0][1] = min(esquinas[0][1], ptos[-1][1])
			esquinas[1][0] = max(esquinas[1][0], ptos[-1][0])
			esquinas[1][1] = max(esquinas[1][1], ptos[-1][1])
	for pto in ptos:
		if esquinas[0][0] <= pto[0] <= esquinas[1][0] and (pto[1] == esquinas[0][1] or pto[1] == esquinas[1][1]):
			continue
		if esquinas[0][1] <= pto[1] <= esquinas[1][1] and (pto[0] == esquinas[0][0] or pto[0] == esquinas[1][0]):
			continue
		print('NO')
		break
	else:
		print('YES')


q = int(input())
for _ in range(q):
	t = int(input())
	points = []
	for __ in range(t):
		(a, b) = [int(x) for x in input().split()]
		points.append((a, b))
	x_min = min([a for (a, b) in points])
	x_max = max([a for (a, b) in points])
	y_min = min([b for (a, b) in points])
	y_max = max([b for (a, b) in points])
	for (a, b) in points:
		if a in [x_min, x_max] and y_min <= b <= y_max:
			continue
		if b in [y_min, y_max] and x_min <= a <= x_max:
			continue
		print('NO')
		break
	else:
		print('YES')


q = int(input())
for z in range(q):
	n = int(input())
	X = []
	Y = []
	for q in range(n):
		(x, y) = list(map(int, input().split()))
		X.append(x)
		Y.append(y)
	x1 = min(X)
	x2 = max(X)
	y1 = min(Y)
	y2 = max(Y)
	if n == 1:
		print('YES')
	else:
		answer = 'YES'
		for i in range(n):
			Xcour = X[i]
			Ycour = Y[i]
			if (Xcour == x1 or Xcour == x2) and (y1 <= Ycour and Ycour <= y2):
				pass
			elif (Ycour == y1 or Ycour == y2) and (x1 <= Xcour and Xcour <= x2):
				pass
			else:
				answer = 'NO'
		print(answer)


Q = int(input())

def calc(points):
	min_x = max_x = points[0][0]
	min_y = max_y = points[0][1]
	for pt in points[1:]:
		if pt[0] < min_x:
			min_x = pt[0]
		if pt[0] > max_x:
			max_x = pt[0]
		if pt[1] < min_y:
			min_y = pt[1]
		if pt[1] > max_y:
			max_y = pt[1]
	for pt in points:
		if min_y < pt[1] < max_y and min_x < pt[0] < max_x:
			return False
		if min_x < pt[0] < max_x and min_y < pt[1] < max_y:
			return False
	return True
for i in range(Q):
	cnt = int(input())
	points = [tuple(map(int, input().split())) for i in range(cnt)]
	print('YES' if calc(points) else 'NO')


q = int(input().strip())
while q > 0:
	n = int(input().strip())
	plusPetitX = float('inf')
	plusPetitY = float('inf')
	plusGrandX = -float('inf')
	plusGrandY = -float('inf')
	l = []
	possible = True
	for n0 in range(n):
		(x, y) = [int(i) for i in input().strip().split(' ')]
		if x < plusPetitX:
			plusPetitX = x
		if x > plusGrandX:
			plusGrandX = x
		if y < plusPetitY:
			plusPetitY = y
		if y > plusGrandY:
			plusGrandY = y
		l.append((x, y))
	for pair in l:
		if (pair[0] != plusPetitX and pair[0] != plusGrandX) and pair[1] != plusPetitY and (pair[1] != plusGrandY):
			possible = False
			break
	if possible:
		print('YES')
	else:
		print('NO')
	q -= 1


from math import atan2, degrees, pi

def get_angle(x1, y1, x2, y2):
	dx = x2 - x1
	dy = y2 - y1
	rads = atan2(-dy, dx)
	rads %= 2 * pi
	degs = degrees(rads)
	return degs

def get_dist(x1, y1, x2, y2):
	minx = min(x1, x2)
	maxx = max(x1, x2)
	miny = min(y1, y2)
	maxy = max(y1, y2)
	return abs(maxx - minx) + abs(maxy - miny)
q = int(input())
for i in range(q):
	n = int(input())
	X = []
	Y = []
	dist = {}
	for j in range(n):
		(x, y) = list(map(int, input().split()))
		X.append(x)
		Y.append(y)
	minx = min(X)
	maxx = max(X)
	miny = min(Y)
	maxy = max(Y)
	rect = True
	for j in range(n):
		if X[j] == minx or X[j] == maxx or Y[j] == miny or (Y[j] == maxy):
			rect = True
		else:
			rect = False
			break
	if rect:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	poi = []
	maxx = maxy = -100000
	minx = miny = 100000
	for _ in range(n):
		(x, y) = map(int, input().split())
		poi.append((x, y))
		if x > maxx:
			maxx = x
		if x < minx:
			minx = x
		if y > maxy:
			maxy = y
		if y < miny:
			miny = y
	flag = 1
	for p in poi:
		if p[0] == maxx or p[0] == minx or p[1] == maxy or (p[1] == miny):
			continue
		else:
			flag = 0
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')


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

def ri():
	return int(input())

class Point(object):

	def __init__(self, x, y):
		self.x = x
		self.y = y

	def __repr__(self):
		return 'Point(%d, %d)' % (self.x, self.y)

def solve(n, points):
	(min_x, max_x) = (min(points, key=lambda p: p.x).x, max(points, key=lambda p: p.x).x)
	(min_y, max_y) = (min(points, key=lambda p: p.y).y, max(points, key=lambda p: p.y).y)
	for p in points:
		if p.x not in (min_x, max_x):
			if p.y not in (min_y, max_y):
				return 'NO'
	return 'YES'

def main():
	t = ri()
	for _ in range(t):
		n = ri()
		points = [Point(*rints()) for _ in range(n)]
		print(solve(n, points))
main()


def solve(xs, ys):
	for (x, y) in zip(xs, ys):
		if x > min(xs) and x < max(xs):
			if y > min(ys) and y < max(ys):
				return 'NO'
	return 'YES'
q = int(input())
for _ in range(q):
	n = int(input())
	xs = []
	ys = []
	for i in range(n):
		(x, y) = list(map(int, input().strip().split(' ')))
		xs.append(x)
		ys.append(y)
	result = solve(xs, ys)
	print(result)


import sys
Q = int(input())
for q in range(Q):
	N = int(input())
	points = []
	point_count = 0
	minx = float('inf')
	miny = float('inf')
	maxx = float('-inf')
	maxy = float('-inf')
	for i in range(N):
		point = [int(i) for i in input().strip().split()]
		minx = min(minx, point[0])
		maxx = max(maxx, point[0])
		miny = min(miny, point[1])
		maxy = max(maxy, point[1])
		points += [point]
		point_count += 1

	def valid():
		for p in points:
			if p[0] != minx and p[0] != maxx and (p[1] != miny) and (p[1] != maxy):
				return False
		return True
	print('YES' if valid() else 'NO')


q = int(input())
for _ in range(q):
	n = int(input())
	xs = []
	ys = []
	for _ in range(n):
		(x, y) = map(int, input().split())
		xs.append(x)
		ys.append(y)
	xmax = max(xs)
	ymax = max(ys)
	xmin = min(xs)
	ymin = min(ys)
	flag = True
	for i in range(n):
		if xs[i] != xmax and xs[i] != xmin and (ys[i] != ymax) and (ys[i] != ymin):
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	i = int(input())
	distinct = {}
	points = []
	(xmax, xmin, ymax, ymin) = (-999999, 999999, -999999, 999999)
	for i in range(i):
		(x, y) = list(map(int, input().split()))
		xmax = max(xmax, x)
		xmin = min(xmin, x)
		ymax = max(ymax, y)
		ymin = min(ymin, y)
		points.append((x, y))
	rect = True
	for point in points:
		(x, y) = (point[0], point[1])
		if x == xmin or x == xmax or y == ymin or (y == ymax):
			continue
		else:
			rect = False
			break
	if rect:
		print('YES')
	else:
		print('NO')


t = int(input())
for z in range(t):
	count = 0
	x_cord = []
	y_cord = []
	q = int(input())
	arr = []
	for x in range(q):
		arr_t = [int(i) for i in input().split()]
		arr.append(arr_t)
	for x in range(q):
		x_cord.append(arr[x][0])
	for y in range(q):
		y_cord.append(arr[y][1])
	min_x = min(x_cord)
	min_y = min(y_cord)
	max_x = max(x_cord)
	max_y = max(y_cord)
	for x in range(q):
		if arr[x][0] == min_x or arr[x][1] == min_y or arr[x][0] == max_x or (arr[x][1] == max_y):
			count += 1
	if count == q:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	x = []
	y = []
	for j in range(n):
		dot = list(map(int, input().split()))
		x.append(dot[0])
		y.append(dot[1])
	max_x = max(x)
	min_x = min(x)
	min_y = min(y)
	max_y = max(y)
	result = True
	for k in range(len(x)):
		if x[k] != min_x and x[k] != max_x and (y[k] != min_y) and (y[k] != max_y):
			result = False
			break
	if result:
		print('YES')
	else:
		print('NO')


queries = int(input())
for query in range(queries):
	n = int(input())
	xs = []
	ys = []
	points = []
	for p in range(n):
		(x, y) = map(int, input().split())
		xs.append(x)
		ys.append(y)
		points.append((x, y))
	for p in points:
		if p[0] != min(xs) and p[0] != max(xs) and (p[1] != min(ys)) and (p[1] != max(ys)):
			print('NO')
			break
	else:
		print('YES')


from itertools import chain
q = int(input())
for iter1 in range(q):
	ans = True
	n = int(input())
	a = [tuple(map(int, input().split())) for i in range(n)]
	x = [t[0] for t in a]
	y = [t[1] for t in a]
	xmin = min(x)
	xmax = max(x)
	ymin = min(y)
	ymax = max(y)
	for (p, q) in a:
		if (p != xmin and p != xmax) and (q != ymin and q != ymax):
			print('NO')
			ans = False
			break
	if ans:
		print('YES')


q = int(input())
for t in range(q):
	n = int(input())
	data = []
	for i in range(n):
		data.append([int(x) for x in input().split()])
	answer = 'YES'
	minx = min(data, key=lambda x: x[0])[0]
	maxx = max(data, key=lambda x: x[0])[0]
	miny = min(data, key=lambda x: x[1])[1]
	maxy = max(data, key=lambda x: x[1])[1]
	for p in data:
		if minx < p[0] < maxx and miny < p[1] < maxy:
			answer = 'NO'
			break
	print(answer)


q = int(input())
A = []
for i in range(q):
	n = int(input())
	X = []
	Y = []
	for j in range(n):
		(x, y) = map(int, input().split())
		X.append(x)
		Y.append(y)
	xmin = min(X)
	xmax = max(X)
	ymin = min(Y)
	ymax = max(Y)
	for i in range(n):
		if (X[i] == xmin or X[i] == xmax) or (Y[i] == ymin or Y[i] == ymax):
			ans = 'YES'
		else:
			ans = 'NO'
			break
	A.append(ans)
for i in A:
	print(i)


queries = int(input().strip())

def CheckRectangle(points):
	(x_list, y_list) = ([], [])
	for (x, y) in points:
		x_list.append(x)
		y_list.append(y)
	x_min = min(x_list)
	x_max = max(x_list)
	y_min = min(y_list)
	y_max = max(y_list)
	for (x, y) in points:
		if x != x_min and x != x_max:
			if y != y_min and y != y_max:
				return 'NO'
		if y != y_min and y != y_max:
			if x != x_min and x != x_max:
				return 'NO'
	return 'YES'
for q in range(queries):
	n = int(input().strip())
	points = []
	for i in range(n):
		(x, y) = list(map(int, input().strip().split()))
		points.append((x, y))
	print(CheckRectangle(points))


n = int(input())
for i in range(n):
	xpoints = []
	flag = True
	ypoints = []
	x1 = []
	arr = []
	y1 = []
	q = int(input())
	for j in range(q):
		(x, y) = [int(_) for _ in input().split()]
		arr.append((x, y))
		x1.append(x)
		y1.append(y)
	xmin = min(x1)
	xmax = max(x1)
	ymin = min(y1)
	ymax = max(y1)
	for j in arr:
		if j[0] != xmin and j[0] != xmax and (j[1] != ymin) and (j[1] != ymax):
			flag = False
	if flag:
		print('YES')
	else:
		print('NO')


Q = int(input())
for _ in range(Q):
	N = int(input())
	L = []
	for _ in range(N):
		(x, y) = [int(n) for n in input().split()]
		L.append((x, y))
	top = max((y for (x, y) in L))
	bot = min((y for (x, y) in L))
	left = min((x for (x, y) in L))
	right = max((x for (x, y) in L))
	bad = False
	for (x, y) in L:
		if x == left or x == right:
			if y > top and y < top:
				bad = True
		elif y == top or y == bot:
			if x < left or x > right:
				bad = True
		else:
			bad = True
	print('NO' if bad else 'YES')


q = int(input())
for _ in range(q):
	n = int(input())
	x = []
	y = []
	f = 0
	for i in range(n):
		(t1, t2) = [int(i) for i in input().split()]
		x.append(t1)
		y.append(t2)
	(x1, x2) = (min(x), max(x))
	(y1, y2) = (min(y), max(y))
	for i in range(n):
		c = 0
		if y1 <= y[i] <= y2 and (x[i] == x1 or x[i] == x2):
			c = 1
		elif x1 <= x[i] <= x2 and (y[i] == y1 or y[i] == y2):
			c = 1
		else:
			c = 0
		if c == 0:
			f = 1
			print('NO')
			break
	if f == 0:
		print('YES')


def solve(min_x, max_x, min_y, max_y, points):
	for (x, y) in points:
		if min_x < x < max_x and min_y < y < max_y:
			return 'NO'
	return 'YES'
t = int(input())
for _ in range(t):
	n = int(input())
	points = []
	(min_x, max_x, min_y, max_y) = (None, None, None, None)
	for i in range(n):
		(x, y) = map(int, input().split())
		points.append((x, y))
		if min_x == None or x < min_x:
			min_x = x
		if max_x == None or x > max_x:
			max_x = x
		if min_y == None or y < min_y:
			min_y = y
		if max_y == None or y > max_y:
			max_y = y
	print(solve(min_x, max_x, min_y, max_y, points))


for t in range(int(input().strip())):
	(x, y) = ([], [])
	for q in range(int(input().strip())):
		(a, b) = map(int, input().strip().split())
		x.append(a)
		y.append(b)
	(a, b, c, d) = (max(x), max(y), min(x), min(y))
	f = 1
	for i in range(len(x)):
		(m, n) = (x[i], y[i])
		if m < a and m > c and (n < b) and (n > d):
			f = 0
			break
		elif m > a or m < c or n > b or (n < d):
			f = 0
			break
	if f == 0:
		print('NO')
	else:
		print('YES')


q = int(input())
for k in range(q):
	n = int(input())
	x = []
	y = []
	(cx, cy) = (0, 0)
	for i in range(n):
		(a, b) = input().strip().split(' ')
		(a, b) = (int(a), int(b))
		x.append(a)
		y.append(b)
	min_x = min(x)
	min_y = min(y)
	mx = max(x)
	my = max(y)
	for i in range(len(x)):
		if x[i] != min_x and x[i] != mx:
			if y[i] == min_y or y[i] == my:
				cx = cx
			else:
				cx += 1
				break
		if y[i] != min_y and y[i] != my:
			if x[i] == min_x or x[i] == mx:
				cy = cy
			else:
				cy += 1
				break
	if cx == 0 and cy == 0:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	n = int(input())
	X = []
	Y = []
	ts = []
	for i in range(n):
		(x, y) = [int(x) for x in input().split()]
		ts.append((x, y))
		X.append(x)
		Y.append(y)
	maxX = max(X)
	maxY = max(Y)
	minX = min(X)
	minY = min(Y)
	cbd = True
	for p in ts:
		if p[0] == maxX or p[0] == minX:
			if p[1] >= minY and p[1] <= maxY:
				cbd = True
			else:
				cbd = False
				break
		elif p[1] == minY or p[1] == maxY:
			cbd = True
		else:
			cbd = False
			break
	if cbd:
		print('YES')
	else:
		print('NO')


N = int(input())
for i in range(N):
	p = int(input())
	xcor = []
	ycor = []
	for j in range(p):
		(m, n) = [int(x) for x in input().split(' ')]
		xcor.append(m)
		ycor.append(n)
	xmin = min(xcor)
	xmax = max(xcor)
	ymin = min(ycor)
	ymax = max(ycor)
	d = 0
	for k in range(len(xcor)):
		if xcor[k] == xmin or xcor[k] == xmax:
			continue
		elif ycor[k] == ymin or ycor[k] == ymax:
			continue
		else:
			d = 1
			break
	if d == 1:
		print('NO')
	else:
		print('YES')


nq = int(input().strip())
for q in range(nq):
	np = int(input().strip())
	p = [tuple((int(x) for x in input().strip().split())) for i in range(np)]
	(x0, x1) = (min((x for (x, y) in p)), max((x for (x, y) in p)))
	(y0, y1) = (min((y for (x, y) in p)), max((y for (x, y) in p)))
	result = 'YES'
	for (x, y) in p:
		if x == x0 or x == x1 or y == y0 or (y == y1):
			continue
		else:
			result = 'NO'
			break
	print(result)


q = int(input())
for i in range(q):
	p = int(input())
	ps = []
	(minx, miny, maxx, maxy) = (100000, 100000, -100000, -100000)
	res = 'YES'
	for j in range(p):
		pp = [int(x) for x in input().split()]
		minx = min(minx, pp[0])
		miny = min(miny, pp[1])
		maxx = max(maxx, pp[0])
		maxy = max(maxy, pp[1])
		ps.append(pp)
	for pp in ps:
		if not (pp[0] == maxx or pp[0] == minx or pp[1] == miny or (pp[1] == maxy)):
			res = 'NO'
	print(res)


def solve():
	n = int(input())
	p = []
	x1 = 100000
	x2 = -100000
	y1 = 100000
	y2 = -100000
	for i in range(n):
		(x, y) = map(int, input().split())
		x1 = min(x1, x)
		x2 = max(x2, x)
		y1 = min(y1, y)
		y2 = max(y2, y)
		p.append([x, y])
	if x1 == x2 or y1 == y2:
		return 'YES'
	if n <= 2:
		return 'YES'
	for i in range(n):
		if p[i][1] == y1 or p[i][1] == y2:
			pass
		elif p[i][0] == x1 or p[i][0] == x2:
			pass
		else:
			return 'NO'
	return 'YES'
for i in range(int(input())):
	print(solve())


q = int(input())
for i in range(q):
	n = int(input())
	X = [1] * n
	Y = [1] * n
	for j in range(n):
		(x, y) = [int(k) for k in input().strip().split()]
		X[j] = x
		Y[j] = y
	xmax = max(X)
	xmin = min(X)
	ymax = max(Y)
	ymin = min(Y)
	for k in range(n):
		if not (X[k] == xmax or X[k] == xmin or Y[k] == ymax or (Y[k] == ymin)):
			print('NO')
			break
		if k == n - 1:
			print('YES')


from operator import itemgetter
import math

def dist(x1, y1, x2, y2):
	return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

def isOnline(Ax, Ay, Bx, By, Cx, Cy):
	return dist(Ax, Ay, Cx, Cy) + dist(Bx, By, Cx, Cy) == dist(Ax, Ay, Bx, By)
for __ in range(int(input())):
	points = []
	for __ in range(int(input())):
		(x, y) = map(int, input().split())
		points.append((x, y))
	lx = min(points, key=itemgetter(0))[0]
	ly = min(points, key=itemgetter(1))[1]
	hx = max(points, key=itemgetter(0))[0]
	hy = max(points, key=itemgetter(1))[1]
	(x1, y1) = (lx, hy)
	(x2, y2) = (hx, hy)
	(x3, y3) = (hx, ly)
	(x4, y4) = (lx, ly)
	online = True
	for point in points:
		(x, y) = (point[0], point[1])
		if not (isOnline(x1, y1, x2, y2, x, y) or isOnline(x2, y2, x3, y3, x, y) or isOnline(x3, y3, x4, y4, x, y) or isOnline(x4, y4, x1, y1, x, y)):
			online = False
			break
	print('YES' if online else 'NO')


q = int(input())
for _ in range(q):
	n = int(input())
	nums = [[int(x) for x in input().strip().split()] for i in range(n)]
	min_x = min([nums[x][0] for x in range(n)])
	max_x = max([nums[x][0] for x in range(n)])
	min_y = min([nums[x][1] for x in range(n)])
	max_y = max([nums[x][1] for x in range(n)])
	good = True
	for (x, y) in nums:
		if x == min_x and y >= min_y and (y <= max_y):
			pass
		elif x == max_x and y >= min_y and (y <= max_y):
			pass
		elif y == min_y and x >= min_x and (x <= max_x):
			pass
		elif y == max_y and x >= min_x and (x <= max_x):
			pass
		else:
			good = False
	if good:
		print('YES')
	else:
		print('NO')


def load(q):
	r = []
	for i in range(q):
		(x, y) = map(int, input().split())
		r.append((x, y))
	return r

def solve(pairs):
	(right, top) = (-100000, -100000)
	(left, bottom) = (100000, 100000)
	for (x, y) in pairs:
		right = max(right, x)
		top = max(top, y)
		left = min(left, x)
		bottom = min(bottom, y)
	for (x, y) in pairs:
		if left < x < right and (y != top and y != bottom):
			return False
		if bottom < y < top and (x != left and x != right):
			return False
	return True
for _ in range(int(input())):
	print('YES' if solve(load(int(input()))) else 'NO')


import math
q = int(input())
i = 0
while i < q:
	n = int(input())
	X = []
	Y = []
	j = 0
	while j < n:
		(x, y) = input().strip().split(' ')
		x = int(x)
		y = int(y)
		X.append(x)
		Y.append(y)
		j += 1
	x0 = min(X)
	y0 = min(Y)
	x3 = max(X)
	y3 = max(Y)
	k = 0
	flag = 0
	while k < len(X):
		if X[k] == x0 and (y <= y3 and y >= y0) or (X[k] == x3 and (y <= y3 and y >= y0)) or (Y[k] == y0 and (x <= x3 and x >= x0)) or (Y[k] == y3 and (x <= x3 and x >= x0)):
			k += 1
			continue
		else:
			flag = 1
			print('NO')
			break
	if flag == 0:
		print('YES')
	i += 1


Q = int(input())
for q in range(Q):
	N = int(input())
	s = []
	x_val = []
	y_val = []
	for n in range(N):
		(x, y) = [int(i) for i in input().split()]
		s += [(x, y)]
		x_val += [x]
		y_val += [y]
	x_val.sort()
	y_val.sort()
	for i in s:
		if i[0] not in [x_val[0], x_val[-1]] and i[1] not in [y_val[0], y_val[-1]]:
			print('NO')
			break
	else:
		print('YES')


import sys
q = int(input().strip())
for i in range(q):
	n = int(input().strip())
	points = []
	xs = []
	ys = []
	for j in range(n):
		(x, y) = input().strip().split(' ')
		(x, y) = [int(x), int(y)]
		points.append((x, y))
		xs.append(x)
		ys.append(y)
	if n <= 2:
		print('YES')
		continue
	min_y = min(ys)
	ys = [y - min_y for y in ys]
	min_x = min(xs)
	xs = [x - min_x for x in xs]
	for k in range(n):
		points[k] = (xs[k], ys[k])
	max_y = max(ys)
	max_x = max(xs)
	count_y = ys.count(max_y)
	count_x = xs.count(max_x)
	if count_y < n and max_y == 0 or (count_x < n and max_x == 0):
		print('NO')
		sys.exit(0)
	yes = True
	for (x, y) in points:
		if x in [0, max_x] and y in range(max_y + 1) or (y in [0, max_y] and x in range(max_x + 1)):
			continue
		yes = False
		break
	if yes:
		print('YES')
	else:
		print('NO')


q = int(input())
for c in range(0, q):
	n = int(input())
	x = []
	y = []
	for k in range(0, n):
		coord = input().split()
		x.append(int(coord[0]))
		y.append(int(coord[1]))
	x_min = min(x)
	x_max = max(x)
	y_min = min(y)
	y_max = max(y)
	q = True
	for i in range(0, n):
		if x[i] != x_min and x[i] != x_max and (y[i] != y_min) and (y[i] != y_max):
			q = False
	if q:
		print('YES')
	else:
		print('NO')


def ans():
	for _ in range(int(input())):
		points = tuple((tuple(map(int, input().split())) for _ in range(int(input()))))
		(maxX, maxY) = map(max, zip(*points))
		(minX, minY) = map(min, zip(*points))
		yield ('NO' if any((maxX != x != minX and maxY != y != minY for (x, y) in points)) else 'YES')
print('\n'.join(ans()))


q = int(input())
for _q in range(q):
	n = int(input())
	(arr_x, arr_y) = ([], [])
	for _n in range(n):
		(x, y) = list(map(int, input().strip().split(' ')))
		arr_x.append(x)
		arr_y.append(y)
	(max_x, min_x, max_y, min_y) = (max(arr_x), min(arr_x), max(arr_y), min(arr_y))
	is_rect = True
	for i in range(n):
		if arr_x[i] not in [max_x, min_x] and arr_y[i] not in [max_y, min_y]:
			is_rect = False
	print('YES' if is_rect else 'NO')


t = int(input())
for tp in range(t):
	n = int(input())
	lx = []
	ly = []
	for i in range(n):
		line = input()
		(x, y) = line.split()
		(x, y) = (int(x), int(y))
		lx.append(x)
		ly.append(y)
	sortx = lx[:]
	sorty = ly[:]
	sortx.sort()
	sorty.sort()
	x1 = sortx[0]
	x2 = sortx[n - 1]
	y1 = sorty[0]
	y2 = sorty[n - 1]
	flag = 1
	for i in range(n):
		if lx[i] == x1 or lx[i] == x2:
			if ly[i] >= y1 and ly[i] <= y2:
				pass
			else:
				print('NO')
				flag = 0
				break
		elif lx[i] >= x1 and lx[i] <= x2:
			if ly[i] == y1 or ly[i] == y2:
				pass
			else:
				print('NO')
				flag = 0
				break
		else:
			print('NO')
			flag = 0
			break
	if flag:
		print('YES')


def main():
	for _ in range(int(input())):
		p = [list(map(int, input().split())) for j in range(int(input()))]
		(px, py) = zip(*p)
		x0 = min(px)
		x1 = max(px)
		y0 = min(py)
		y1 = max(py)
		result = all((x in (x0, x1) or y in (y0, y1) for (x, y) in p))
		print('YES' if result else 'NO')
main()


q = int(input())
for r in range(q):
	n = int(input())
	xvals = []
	yvals = []
	for i in range(n):
		(x, y) = map(int, input().split())
		xvals.append(x)
		yvals.append(y)
	xmin = min(xvals)
	xmax = max(xvals)
	ymin = min(yvals)
	ymax = max(yvals)
	for i in range(n):
		x = xvals[i]
		y = yvals[i]
		if x > xmin and x < xmax and (y > ymin) and (y < ymax):
			print('NO')
			break
	else:
		print('YES')


q = int(input())
for _ in range(q):
	flag = 0
	mxx = mxy = (-100000, -100000)
	mnx = mny = (100000, 100000)
	p = []
	n = int(input())
	for _ in range(n):
		(a, b) = input().strip().split(' ')
		(a, b) = [int(a), int(b)]
		if a < mnx[0]:
			mnx = (a, b)
		if b < mny[1]:
			mny = (a, b)
		if a > mxx[0]:
			mxx = (a, b)
		if b > mxy[1]:
			mxy = (a, b)
		p.append((a, b))
	for (a, b) in p:
		if a != mxx[0] and a != mnx[0] and (b != mxy[1]) and (b != mny[1]):
			flag = 1
	if flag == 0:
		print('YES')
	else:
		print('NO')


import sys
q = int(input())
while q:
	n = int(input())
	x_s = []
	y_s = []
	for i in range(n):
		(x, y) = [int(elem) for elem in sys.stdin.readline().strip().split()]
		x_s.append(x)
		y_s.append(y)
	x_min = min(x_s)
	x_max = max(x_s)
	y_min = min(y_s)
	y_max = max(y_s)
	is_rectangle = True
	for i in range(n):
		if not is_rectangle:
			break
		x = x_s[i]
		y = y_s[i]
		if y != y_min and y != y_max and (x != x_min) and (x != x_max):
			is_rectangle = False
			continue
		if (y == y_min or y == y_max) and (x >= x_min and x <= x_max) or ((x == x_min or x == x_max) and (y >= y_min and y <= y_max)):
			continue
		else:
			is_rectangle = False
	if is_rectangle:
		print('YES')
	else:
		print('NO')
	q -= 1


def solve(Ps):
	x0 = min((x for (x, y) in Ps))
	x1 = max((x for (x, y) in Ps))
	y0 = min((y for (x, y) in Ps))
	y1 = max((y for (x, y) in Ps))
	return all((x == x0 or x == x1 or y == y0 or (y == y1) for (x, y) in Ps))
q = int(input())
for _ in range(q):
	Ps = list((tuple(map(int, input().split())) for _ in range(int(input()))))
	if solve(Ps):
		print('YES')
	else:
		print('NO')


from collections import namedtuple
Point = namedtuple('Point', 'x y')
q = int(input())
for _ in range(q):
	n = int(input())
	l = []
	top = bot = left = right = 0
	for _k in range(n):
		(x, y) = input().split()
		l.append(Point(int(x), int(y)))
	top = max((ll.y for ll in l))
	bot = min((ll.y for ll in l))
	left = min((ll.x for ll in l))
	right = max((ll.x for ll in l))
	for ll in l:
		if ll.x != left and ll.x != right and (ll.y != top) and (ll.y != bot):
			print('NO')
			break
	else:
		print('YES')


import sys
import math

def read_one():
	return int(input().strip())

def read_all():
	x = input().strip().split(' ')
	return [int(i) for i in x]

def execute(points):
	if len(points) == 0:
		return 'YES'
	xs = [p[0] for p in points]
	ys = [p[1] for p in points]
	(xmin, xmax) = (min(xs), max(xs))
	(ymin, ymax) = (min(ys), max(ys))
	for p in points:
		if p[0] not in [xmin, xmax] and p[1] not in [ymin, ymax]:
			return 'NO'
	return 'YES'
q = read_one()
for _ in range(q):
	n = read_one()
	points = [read_all() for _ in range(n)]
	r = execute(points)
	print(r)


class Point:

	def __init__(self, x, y):
		self.x = x
		self.y = y

def on_rectangle(points):
	xmin = min((p.x for p in points))
	xmax = max((p.x for p in points))
	ymin = min((p.y for p in points))
	ymax = max((p.y for p in points))
	for p in points:
		if (p.x == xmin or p.x == xmax) and ymin <= p.y <= ymax:
			continue
		if (p.y == ymin or p.y == ymax) and xmin <= p.x <= xmax:
			continue
		return False
	return True
T = int(input())
for t in range(T):
	n = int(input())
	points = []
	for i in range(n):
		(x, y) = map(int, input().split())
		points.append(Point(x, y))
	if on_rectangle(points):
		print('YES')
	else:
		print('NO')


Q = int(input())
from math import inf

def square(P):
	xmin = inf
	xmax = -inf
	ymin = inf
	ymax = -inf
	for p in P:
		xmin = min(xmin, p[0])
		xmax = max(xmax, p[0])
		ymin = min(ymin, p[1])
		ymax = max(ymax, p[1])
	for p in P:
		if (xmin < p[0] < xmax) & (ymin < p[1] < ymax):
			return False
		if (p[0] < xmin) | (p[0] > xmax) | (p[1] < ymin) | (p[1] > ymax):
			return False
	return True
for q0 in range(Q):
	N = int(input())
	P = []
	for n0 in range(N):
		(x, y) = (int(a) for a in input().split())
		P.append((x, y))
	res = square(P)
	if res:
		print('YES')
	else:
		print('NO')


num_probs = int(input())
for _ in range(num_probs):
	num_pts = int(input())
	xs = []
	ys = []
	pts = []
	for _ in range(num_pts):
		(x, y) = (int(x) for x in input().split())
		xs.append(x)
		ys.append(y)
		pts.append((x, y))
	x_min = min(xs)
	x_max = max(xs)
	y_min = min(ys)
	y_max = max(ys)
	good = True
	for (x, y) in pts:
		if x != x_min and x != x_max and (y != y_min) and (y != y_max):
			good = False
			break
	if good:
		print('YES')
	else:
		print('NO')


import sys

def process_query():
	n = int(input())
	coords = []
	min_y = min_x = +sys.maxsize
	max_y = max_x = -sys.maxsize
	for i in range(n):
		(x, y) = map(int, input().split())
		min_x = min(min_x, x)
		max_x = max(max_x, x)
		min_y = min(min_y, y)
		max_y = max(max_y, y)
		coords.append((x, y))
	for (x, y) in coords:
		if x > min_x and x < max_x and (y > min_y) and (y < max_y):
			return False
	return True

def main():
	q = int(input())
	for idx in range(q):
		print('YES' if process_query() else 'NO')
main()


import sys

def solve(pp):
	x1 = min((x for (x, _) in pp))
	x2 = max((x for (x, _) in pp))
	y1 = min((y for (_, y) in pp))
	y2 = max((y for (_, y) in pp))
	if x1 == x2 or y1 == y2:
		return True
	for (x, y) in pp:
		if x not in (x1, x2) and y not in (y1, y2):
			return False
	return True
q = int(input())
for _ in range(q):
	pp = list()
	n = int(input())
	for _ in range(n):
		(x, y) = map(int, input().split())
		pp.append((x, y))
	if solve(pp):
		print('YES')
	else:
		print('NO')


q = int(input())
for _ in range(q):
	n = int(input())
	d = []
	for i in range(n):
		d.append(list(map(int, input().split())))
	if n < 3:
		print('YES')
	else:
		(minx, maxy, maxx, miny) = (*d[0], *d[0])
		(iminx, imaxx, iminy, imaxy) = [0] * 4
		for i in range(len(d)):
			if minx > d[i][0]:
				minx = d[i][0]
				iminx = i
			if maxx < d[i][0]:
				maxx = d[i][0]
				imaxx = i
			if maxy < d[i][1]:
				maxy = d[i][1]
				imaxy = i
			if miny > d[i][1]:
				miny = d[i][1]
				iminy = i
		if maxy == miny or maxx == minx:
			print('YES')
		else:
			f = True
			for i in d:
				if minx != i[0] != maxx and miny != i[1] != maxy:
					f = False
					break
			print('YES' if f else 'NO')


for cnt in range(int(input())):
	n = int(input())
	d = []
	t = list(map(int, input().split()))
	d.append(t)
	xmin = xmax = t[0]
	ymin = ymax = t[1]
	for i in range(n - 1):
		t = list(map(int, input().split()))
		(xmin, xmax) = (min(xmin, t[0]), max(xmax, t[0]))
		(ymin, ymax) = (min(ymin, t[1]), max(ymax, t[1]))
		d.append(t)
	(xr, yr) = (range(xmin, xmax + 1), range(ymin, ymax + 1))
	for t in d:
		if t[0] == xmin or t[0] == xmax:
			if t[1] not in yr:
				print('NO')
				break
		elif t[1] == ymin or t[1] == ymax:
			if t[0] not in xr:
				print('NO')
				break
		else:
			print('NO')
			break
	else:
		print('YES')


queries = int(input().strip())
for q in range(queries):
	points = int(input().strip())
	bottom = float('inf')
	top = -float('inf')
	left = float('inf')
	right = -float('inf')
	pts = []
	for n in range(points):
		(x, y) = [int(i) for i in input().strip().split()]
		if x < left:
			left = x
		if x > right:
			right = x
		if y > top:
			top = y
		if y < bottom:
			bottom = y
		pts.append((x, y))
	flag = 'YES'
	for p in pts:
		if (p[0] != left and p[0] != right) and (p[1] != bottom and p[1] != top):
			flag = 'NO'
	print(flag)
	pts.clear()


q = int(input())
for i in range(q):
	n = int(input())
	xs = list()
	ys = list()
	for j in range(n):
		[x, y] = [int(p) for p in input().split(' ')]
		xs.append(x)
		ys.append(y)
	xmin = min(xs)
	xmax = max(xs)
	ymin = min(ys)
	ymax = max(ys)
	ret = True
	for j in range(n):
		if xs[j] < xmax and xs[j] > xmin and (ys[j] > ymin) and (ys[j] < ymax):
			ret = False
			break
	if ret:
		print('YES')
	else:
		print('NO')


q = int(input())
for i in range(q):
	n = int(input())
	xmin = 100000
	xmax = -100000
	ymin = 100000
	ymax = -10000
	v = []
	for j in range(n):
		[xi, yi] = input().split()
		[xi, yi] = [int(xi), int(yi)]
		v.append([xi, yi])
		if xi < xmin:
			xmin = xi
		if xi > xmax:
			xmax = xi
		if yi < ymin:
			ymin = yi
		if yi > ymax:
			ymax = yi
	ok = True
	for i in range(n):
		if not (v[i][0] == xmin or v[i][0] == xmax or v[i][1] == ymin or (v[i][1] == ymax)):
			ok = False
			break
	if ok:
		print('YES')
	else:
		print('NO')


def check(points, n):
	xmin = min([p[0] for p in points])
	xmax = max([p[0] for p in points])
	ymin = min([p[1] for p in points])
	ymax = max([p[1] for p in points])
	for (x, y) in points:
		if x not in [xmin, xmax] and y not in [ymin, ymax]:
			return False
	return True
for t in range(int(input())):
	n = int(input())
	points = [[int(_) for _ in input().split()] for __ in range(n)]
	print('YES' if check(points, n) else 'NO')


import sys
q = int(input())
for _ in range(q):
	N = int(input())
	NOT = False
	x = []
	y = []
	for _ in range(N):
		(a, b) = map(int, input().split())
		x.append(a)
		y.append(b)
	xmin = min(x)
	xmax = max(x)
	ymin = min(y)
	ymax = max(y)
	for (a, b) in zip(x, y):
		if a != xmin and a != xmax and (b != ymax) and (b != ymin):
			NOT = True
			break
	if not NOT:
		print('YES')
	else:
		print('NO')


def main():
	for i in range(int(input())):
		p = [list(map(int, input().split())) for j in range(int(input()))]
		(px, py) = zip(*p)
		x0 = min(px)
		x1 = max(px)
		y0 = min(py)
		y1 = max(py)
		result = all((x in (x0, x1) or y in (y0, y1) for (x, y) in p))
		print('YES' if result else 'NO')
main()


for _ in range(int(input())):
	(X, Y) = ([], [])
	for _ in range(int(input())):
		(x, y) = map(int, input().split(' '))
		X.append(x)
		Y.append(y)
	min_x = min(X)
	max_x = max(X)
	min_y = min(Y)
	max_y = max(Y)
	ok = True
	for (x, y) in zip(X, Y):
		if x != min_x and x != max_x and (y != min_y) and (y != max_y):
			ok = False
	print('YES' if ok else 'NO')


t = int(input())
for _ in range(t):
	n = int(input())
	points = [tuple(map(int, input().split())) for _ in range(n)]
	(X, Y) = zip(*points)
	(mxx, mnx) = (max(X), min(X))
	(mxy, mny) = (max(Y), min(Y))
	res = all((x in (mxx, mnx) or y in (mxy, mny) for (x, y) in points))
	print('YES' if res else 'NO')


for _ in range(int(input())):
	n = int(input())
	Lx = []
	Ly = []
	for i in range(n):
		(x, y) = map(int, input().split())
		Lx += [x]
		Ly += [y]
	if n == 1 or n == 2:
		print('YES')
	else:
		ymin = min(Ly)
		ymax = max(Ly)
		xmin = min(Lx)
		xmax = max(Lx)
		for i in range(n):
			if Ly[i] != ymin and Ly[i] != ymax and (Lx[i] != xmin) and (Lx[i] != xmax):
				print('NO')
				break
			if i == n - 1:
				print('YES')


import os
import sys

def solve(n, coord):
	xmin = xmax = coord[0][0]
	ymin = ymax = coord[0][1]
	for i in range(n):
		if xmin > coord[i][0]:
			xmin = coord[i][0]
		if xmax < coord[i][0]:
			xmax = coord[i][0]
		if ymin > coord[i][1]:
			ymin = coord[i][1]
		if ymax < coord[i][1]:
			ymax = coord[i][1]
	c = 0
	for i in range(n):
		if (coord[i][0] == xmin or coord[i][0] == xmax) and (coord[i][0] <= ymax or coord[i][0] >= ymin):
			c += 1
		elif (coord[i][1] == ymin or coord[i][1] == ymax) and (coord[i][1] <= xmax or coord[i][1] >= xmin):
			c += 1
	if c == n:
		print('YES')
	else:
		print('NO')
q = int(input())
for q_itr in range(q):
	n = int(input())
	coord = []
	for _ in range(n):
		coord.append(list(map(int, input().rstrip().split())))
	solve(n, coord)


a = int(input())
for i in range(a):
	b = int(input())
	p = list()
	q = list()
	t = 1
	for j in range(b):
		(x, y) = [int(s) for s in input().split()]
		p.append(x)
		q.append(y)
	l = min(p)
	m = max(p)
	n = min(q)
	o = max(q)
	for j in range(b):
		if p[j] == l:
			if q[j] < n or q[j] > o:
				t = 0
				break
		elif p[j] == m:
			if q[j] < n or q[j] > o:
				t = 0
				break
		elif q[j] == n:
			if p[j] < l or p[j] > m:
				t = 0
				break
		elif q[j] == o:
			if p[j] < l or p[j] > m:
				t = 0
				break
		else:
			t = 0
			break
	if t == 1:
		print('YES')
	elif t == 0:
		print('NO')


t = int(input())
for i in range(t):
	a = []
	b = []
	n = int(input())
	for j in range(n):
		(x, y) = map(int, input().split())
		a.append(x)
		b.append(y)
	xmin = min(a)
	ymin = min(b)
	xmax = max(a)
	ymax = max(b)
	for j in range(n):
		if (a[j] != xmin and a[j] != xmax) and (b[j] != ymin and b[j] != ymax):
			print('NO')
			break
	else:
		print('YES')


from typing import List

def solve(arr: List[List[int]]) -> str:
	x_coords = [a[0] for a in arr]
	y_coords = [a[1] for a in arr]
	(x_min, x_max) = (min(x_coords), max(x_coords))
	(y_min, y_max) = (min(y_coords), max(y_coords))
	for point in arr:
		(x, y) = point
		if not (x in {x_min, x_max} or y in {y_min, y_max}):
			return 'NO'
	return 'YES'
for q in range(int(input())):
	coordinates = []
	for _ in range(int(input())):
		coordinates.append(list(map(int, input().strip().split())))
	print(solve(coordinates))