You are given $n$ one-dimensional segments (each segment is denoted by two integers — its endpoints).

Let's define the function $f(x)$ as the number of segments covering point $x$ (a segment covers the point $x$ if $l \le x \le r$, where $l$ is the left endpoint and $r$ is the right endpoint of the segment).

An integer point $x$ is called ideal if it belongs to more segments than any other integer point, i. e. $f(y) < f(x)$ is true for any other integer point $y$.

You are given an integer $k$. Your task is to determine whether it is possible to remove some (possibly zero) segments, so that the given point $k$ becomes ideal.


-----Input-----

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

The first line of each test case contains two integers $n$ and $k$ ($1 \le n, k \le 50$).

Then $n$ lines follow, $i$-th line of them contains two integers $l_i$ and $r_i$ ($1 \le l_i, r_i \le 50$; $l_i \le r_i$) — the endpoints of the $i$-th segment.


-----Output-----

For each test case, print YES if it is possible to remove some (possibly zero) segments, so that the given point $k$ becomes ideal, otherwise print NO.

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
4
4 3
1 3
7 9
2 5
3 6
2 9
1 4
3 7
1 3
2 4
3 5
1 4
6 7
5 5
Output
YES
NO
NO
YES


-----Note-----

In the first example, the point $3$ is already ideal (it is covered by three segments), so you don't have to delete anything.

In the fourth example, you can delete everything except the segment $[5, 5]$.

Difficulty: EASY
Tags: Geometry

Complete search

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
import sys
input = sys.stdin.readline
for tc in range(int(input())):
	(n, k) = map(int, input().split())
	(lb, rb) = (False, False)
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			lb = True
		if r == k:
			rb = True
	print('YES' if lb and rb else 'NO')


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	(s, e) = (0, 0)
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			s += 1
		if r == k:
			e += 1
	if s > 0 and e > 0:
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	solve()


import sys
sys_input = sys.stdin.readline
sys_print = sys.stdout.write

def testcase():
	(n, k) = map(int, sys_input().split())
	lines = [tuple(map(int, sys_input().split())) for _ in range(n)]
	(nst, ned) = (0, 0)
	for (s, e) in lines:
		if s == k:
			nst += 1
		if e == k:
			ned += 1
	if nst > 0 and ned > 0:
		sys_print('YES\n')
	else:
		sys_print('NO\n')
t = int(sys_input())
for _ in range(t):
	testcase()


import sys
input = iter(sys.stdin.read().splitlines()).__next__
TC = int(input())
for tc in range(TC):
	(N, K) = map(int, input().split())
	(starts, ends) = (False, False)
	for i in range(N):
		(l, r) = map(int, input().split())
		if l == K:
			starts = True
		if r == K:
			ends = True
	print('YES' if starts and ends else 'NO')


import sys
input = sys.stdin.readline

def sol(arr, n):
	pass
t = int(input())
for case in range(t):
	(n, k) = list(map(int, input().split()))
	s1 = set()
	s2 = set()
	for i in range(n):
		(x, y) = list(map(int, input().split()))
		s1.add(x)
		s2.add(y)
	if k in s1 and k in s2:
		print('YES')
	else:
		print('NO')


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().strip().split())
	r = False
	rl = False
	rr = False
	for _ in range(n):
		(l, r) = map(int, sys.stdin.readline().strip().split())
		if l == k == r:
			rl = True
			rr = True
		elif l == k:
			rl = True
		elif r == k:
			rr = True
	print('YES' if rl and rr else 'NO')


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

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

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

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

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = inp()
for i in range(t):
	(n, k) = mp()
	(f, f1) = (0, 0)
	for i in range(n):
		(a, b) = mp()
		if b - k == 0:
			f = 1
		if k - a == 0:
			f1 = 1
	if f == 1 and f1 == 1:
		print('YES')
	else:
		print('NO')


import sys
import math as mt
mod = 1000000007

def uno():
	return int(sys.stdin.readline().strip())

def dos():
	return sys.stdin.readline().strip()

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

def cuatro():
	return sys.stdin.readline().strip().split()
for _ in range(uno()):
	(n, k) = tres()
	(cnt, l, r) = (0, -1, 51)
	for i in range(n):
		(a, b) = tres()
		if a <= k <= b:
			cnt += 1
			r = min(r, b)
			l = max(l, a)
	if cnt == 0 or r - l + 1 > 1:
		print('NO')
	else:
		print('YES')


def main():
	for i in range(int(input())):
		(n, k) = [int(x) for x in input().split()]
		(l, r) = (False, False)
		for j in range(n):
			z = input().split()
			if int(z[0]) == k:
				l = True
			if int(z[1]) == k:
				r = True
		if l and r:
			print('YES')
		else:
			print('NO')
main()


from collections import defaultdict
from sys import stdin, stdout
import string
import math
test_cases = int(stdin.readline())
for it in range(test_cases):
	(n, k) = map(int, tuple(stdin.readline().split()))
	(k_covered, left_neighbour_covered, right_neighbour_covered) = (0, 0, 0)
	for i in range(n):
		(l, r) = map(int, tuple(stdin.readline().split()))
		if l > k or k > r:
			continue
		k_covered += 1
		if l <= k + 1 <= r:
			right_neighbour_covered += 1
		if l <= k - 1 <= r:
			left_neighbour_covered += 1
	if right_neighbour_covered >= k_covered or left_neighbour_covered >= k_covered:
		print('NO')
		continue
	print('YES')


import sys

def solve(seg, k):
	(l, r) = (False, False)
	for (a, b) in seg:
		l |= a == k
		r |= b == k
		if l and r:
			return 'YES'
	return 'NO'
n = int(sys.stdin.readline())
for i in range(n):
	(n, k) = map(int, sys.stdin.readline().split())
	seg = []
	for j in range(n):
		(a, b) = map(int, sys.stdin.readline().split())
		seg += [(a, b)]
	print(solve(seg, k))


import sys
import math
import itertools

def solution():
	(n, k) = map(int, input().split())
	ml = []
	mr = []
	kl = 0
	kr = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		ml.append(l)
		mr.append(r)
		if l == k:
			kl += 1
		if r == k:
			kr += 1
	if kl and kr:
		print('YES')
		return
	print('NO')
	return
t = int(input())
for i in range(t):
	solution()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(l1, l2) = ([], [])
	(f, b) = (0, 0)
	for i in range(n):
		l2 = [int(a) for a in input().split()]
		if l2[1] == k:
			f = 1
		if l2[0] == k:
			b = 1
	if f & b:
		print('YES')
	else:
		print('NO')


def slove():
	for _ in range(int(input())):
		(m, n) = map(int, input().split())
		ans_n = 0
		ans_k = 0
		for _ in range(m):
			(na, ko) = map(int, input().split())
			if na == n:
				ans_n += 1
			if ko == n:
				ans_k += 1
		if ans_k != 0 and ans_n != 0:
			print('YES')
		else:
			print('NO')
slove()


t = int(input())
for i in range(t):
	n = input().split()
	k = int(n[1])
	n = int(n[0])
	l = []
	for j in range(n):
		l1 = input().split()
		l.append([int(l1[0]), int(l1[1])])
	(start, end) = (False, False)
	for j in l:
		if j[0] == k and (not start):
			start = True
		if j[1] == k and (not end):
			end = True
	if start and end:
		print('YES')
	else:
		print('NO')


def run_test():
	(n, k) = map(int, input().split())
	end = 0
	start = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			start += 1
		if r == k:
			end += 1
	if start > 0 and end > 0:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	run_test()


def solve():
	(n, k) = map(int, input().split())
	end = start = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			start += 1
		if r == k:
			end += 1
	if start > 0 and end > 0:
		print('YES')
		return
	print('NO')
for t in range(int(input())):
	solve()


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	(p, q) = (0, 0)
	for i in range(a):
		(x, y) = map(int, input().split())
		if x == b:
			p += 1
		if y == b:
			q += 1
	if p > 0 and q > 0:
		print('YES')
	else:
		print('NO')


t = int(input())
import math
for _ in range(0, t):
	inputs = [int(num) for num in input().split()]
	n = inputs[0]
	m = inputs[1]
	list1 = []
	list2 = [0 for i in range(0, 51)]
	x = -1
	power1 = 0
	power2 = 0
	for i in range(0, n):
		inputs = [int(num) for num in input().split()]
		if inputs[0] == m:
			power1 += 1
		if inputs[1] == m:
			power2 += 1
	if power1 >= 1 and power2 >= 1:
		print('YES')
	else:
		print('NO')


a = int(input())
while a:
	(n, k) = map(int, input().split())
	tarun = 0
	kumar = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			tarun += 1
		if r == k:
			kumar += 1
	if tarun > 0 and kumar > 0:
		print('YES')
	else:
		print('NO')
	a -= 1


def idealPoint():
	(end, start) = (0, 0)
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			start += 1
		if r == k:
			end += 1
	if start > 0 and end > 0:
		return 'YES'
	else:
		return 'NO'
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	ans = idealPoint()
	print(ans)
	t = t - 1


def solve():
	(n, k) = map(int, input().split())
	(st, end) = (0, 0)
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			st += 1
		if r == k:
			end += 1
	if st > 0 and end > 0:
		print('YES')
	else:
		print('NO')

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	fx = 0
	startp = 0
	endp = 0
	is2 = False
	for _ in range(n):
		(l, r) = map(int, input().split())
		if k <= r and k >= l:
			fx += 1
		if l == r and l == k:
			is2 = True
		if r == k:
			endp += 1
		if l == k:
			startp += 1
	if is2 and fx == 1:
		print('YES')
	elif startp >= 1 and endp >= 1:
		print('YES')
	elif fx <= 1:
		print('NO')
	else:
		print('NO')


def solve():
	t = 1
	t = int(input())
	while t:
		t -= 1
		(n, k) = [int(x) for x in input().split()]
		rseg_k = lseg_k = 0
		while n:
			n -= 1
			(l, r) = [int(x) for x in input().split()]
			if l == k:
				lseg_k += 1
			if k == r:
				rseg_k += 1
		print('YES' if lseg_k > 0 and rseg_k > 0 else 'NO')
solve()


R = lambda : map(int, input().split())
(t,) = R()
while t:
	t -= 1
	(n, k) = R()
	(a, b) = map(set, zip(*(R() for _ in [0] * n)))
	print('NYOE S'[k in a & b::2])


t = int(input())
while t:
	(n, k) = [int(i) for i in input().split()]
	s = 0
	e = 0
	while n:
		(l, r) = [int(i) for i in input().split()]
		if l == k:
			s += 1
		if r == k:
			e += 1
		n -= 1
	if s > 0 and e > 0:
		print('YES')
	else:
		print('NO')
	t -= 1


def solve():
	t = int(input())
	for _ in range(t):
		left = False
		right = False
		(n, k) = map(int, input().split())
		for _ in range(n):
			(l, r) = map(int, input().split())
			if l == k:
				left = True
			if r == k:
				right = True
		if left and right:
			print('YES')
			continue
		print('NO')

def main():
	solve()
main()


def IdealPoint():
	t = int(input())
	while t:
		t -= 1
		(n, k) = map(int, input().split())
		county = 0
		countx = 0
		while n:
			n -= 1
			(l, r) = map(int, input().split())
			if k == l:
				countx += 1
			if k == r:
				county += 1
		if countx > 0 and county > 0:
			print('YES')
		else:
			print('NO')
IdealPoint()


for t in range(int(input())):
	flag1 = False
	flag2 = False
	(n, k) = map(int, input().split())
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			flag1 = True
		if r == k:
			flag2 = True
	if flag1 and flag2:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	l = [int(x) for x in input().split()]
	pc1 = False
	pc2 = False
	for j in range(l[0]):
		lst = [int(y) for y in input().split()]
		if lst[0] == l[1]:
			pc1 = True
		if lst[1] == l[1]:
			pc2 = True
	if pc1 and pc2:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	(n, k) = map(int, input().strip().split())
	left = False
	right = False
	while n:
		(l, r) = map(int, input().strip().split())
		if l == k:
			left = True
		if r == k:
			right = True
		n -= 1
	if left and right:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	(l, r) = (0, 0)
	for x in range(n):
		(x, y) = map(int, input().split())
		if x == k:
			l = 1
		if y == k:
			r = 1
	if l * r:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	cntl = 0
	cntr = 0
	for j in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			cntl = 1
		if r == k:
			cntr = 1
	if cntl == 1 and cntr == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(c1, c2) = (0, 0)
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			c1 = 1
		if r == k:
			c2 = 1
	if c1 and c2:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	left = right = False
	for _ in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			left = True
		if r == k:
			right = True
	if left and right:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	flag1 = 0
	flag2 = 0
	for j in range(n):
		(l, r) = map(int, input().split())
		if k == l:
			flag1 = 1
		if k == r:
			flag2 = 1
	if flag1 == 1 and flag2 == 1:
		print('YES')
	else:
		print('NO')


tn = int(input())
for i in range(tn):
	[n, x] = [int(y) for y in input().split()]
	c = 0
	m = 0
	for j in range(n):
		p = input().split()
		if int(p[0]) == x:
			c += 1
		if int(p[1]) == x:
			m += 1
	if c >= 1 and m >= 1:
		print('YES')
	else:
		print('NO')


t = int(input())
pts = []
segs = []
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	pts.append(k)
	segs.append([])
	for _ in range(n):
		(l, r) = [int(x) for x in input().split()]
		segs[-1].append((l, r))
for i in range(t):
	(k, part) = (pts[i], segs[i])
	ends = starts = False
	for seg in part:
		ends = seg[0] == k or ends
		starts = seg[1] == k or starts
		if ends and starts:
			print('YES')
			break
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = 0
	e = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			s += 1
		if r == k:
			e += 1
	if s > 0 and e > 0:
		print('YES')
	else:
		print('NO')


def solve():
	(n, k) = map(int, input().split())
	kl = 0
	kr = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			kl = 1
		if r == k:
			kr = 1
	if kl == 1 and kr == 1:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	solve()


T = int(input())
for cnt in range(T):
	(n, k) = map(int, input().split())
	left = []
	right = []
	for i in range(n):
		(segment1, segment2) = map(int, input().split())
		if segment1 <= k and segment2 >= k:
			left.append(segment1)
			right.append(segment2)
	if len(left) == 0 or len(right) == 0:
		print('NO')
	else:
		arr = [max(left), min(right)]
		if arr[0] == arr[1]:
			print('YES')
		else:
			print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = set()
	r = set()
	for j in range(n):
		(a, b) = map(int, input().split())
		l.add(a)
		r.add(b)
	if k in l & r:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lst = []
	for i in range(n):
		lst.append(list(map(int, input().split())))
	Redge = False
	Ledge = False
	for i in range(n):
		if lst[i][1] == k:
			Redge = True
		if lst[i][0] == k:
			Ledge = True
	if Redge and Ledge:
		print('YES')
	else:
		print('NO')


from itertools import *

def check(arr):
	n = len(arr)
	if arr[0] == start and arr[1] == end:
		for i in range(1, n - 1):
			if arr[i] % (i + 1) != 0:
				return 0
		return 1
	else:
		return 0

def func(n):
	lst = []
	for i in range(1, n + 1):
		lst.append(i)
	perm = permutations(lst)
	for i in perm:
		if check(i) == 1:
			print(i)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	flag1 = 0
	flag2 = 0
	flag3 = 0
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == r and l == k:
			flag1 = 1
		if l == k:
			flag2 = 1
		if r == k:
			flag3 = 1
	if flag1:
		print('YES')
	elif flag2 and flag3:
		print('YES')
	else:
		print('NO')


t = int(input())
for z in range(t):
	(n, k) = [int(x) for x in input().split()]
	end = 0
	start = 0
	for _ in range(n):
		(s, e) = [int(x) for x in input().split()]
		if s == k:
			start = 1
		if e == k:
			end = 1
	if start == 1 and end == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
from collections import defaultdict
while t > 0:
	arr = input().split(' ')
	arr = [arr[0], arr[1]]
	n = int(arr[0])
	k = int(arr[1])
	(s, e) = (0, 0)
	while n > 0:
		x = input().split(' ')
		if int(x[0]) == k:
			s += 1
		if int(x[1]) == k:
			e += 1
		n -= 1
	ans = 'YES'
	if s > 0 and e > 0:
		ans = 'YES'
	else:
		ans = 'NO'
	print(ans)
	t -= 1


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	c = [0, 0]
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		if l == k:
			c[0] += 1
		if r == k:
			c[1] += 1
	if c[0] and c[1]:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	(mpL, mpR) = ([0] * 55, [0] * 55)
	ans = 'NO'
	for j in range(n):
		(l, r) = map(int, input().split())
		mpL[l] += 1
		mpR[r] += 1
	if mpL[k] >= 1 and mpR[k] >= 1:
		ans = 'YES'
	print(ans)


def try_prob():
	(e, g) = map(int, input().split())
	ab = 0
	stpoint = 0
	endpoint = 0
	for i in range(e):
		(t, u) = map(int, input().split())
		if t == g:
			stpoint += 1
		if u == g:
			endpoint += 1
	if stpoint > 0 and endpoint > 0:
		ab = 1
		print('YES')
		return
	if ab == 0:
		print('NO')

def main():
	a = int(input())
	for _ in range(a):
		try_prob()
main()


t = int(input())
for z in range(t):
	(n, k) = [int(x) for x in input().split()]
	left = 0
	right = 0
	for y in range(n):
		(l, r) = [int(x) for x in input().split()]
		if l == k:
			left += 1
		if r == k:
			right += 1
	if left >= 1 and right >= 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	count1 = 0
	count2 = 0
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		if k == l:
			count1 += 1
		if k == r:
			count2 += 1
	if count1 > 0 and count2 > 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	le = 0
	ri = 0
	for i in range(n):
		if l[i][0] == k:
			le += 1
		if l[i][1] == k:
			ri += 1
	if le >= 1 and ri >= 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		(l, r) = list(map(int, input().split()))
		if l == k:
			ans |= 1
		if r == k:
			ans |= 2
	if ans == 3:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, k) = map(int, input().split())
	(l, r) = (0, 0)
	for j in range(n):
		(a, b) = map(int, input().split())
		if a == k:
			l += 1
		if b == k:
			r += 1
	print('YES' if l and r else 'NO')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	L_end = R_end = False
	for j in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			L_end = True
		if r == k:
			R_end = True
	if L_end and R_end:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	c = [0, 0]
	for i in range(n):
		(left, right) = list(map(int, input().split()))
		if left == k:
			c[0] += 1
		if right == k:
			c[1] += 1
	if c[0] and c[1]:
		print('YES')
	else:
		print('NO')


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve(a, n, k):
	v1 = any([y == k for (x, y) in a])
	v2 = any([x == k for (x, y) in a])
	return 'YES' if v1 and v2 else 'NO'
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = []
	for __ in range(n):
		(x, y) = map(int, input().split())
		a.append([x, y])
	print(solve(a, n, k))


import sys

def solution():
	(n, k) = map(int, input().split())
	left = 0
	mid = 0
	right = 0
	for _ in range(n):
		seg = tuple(map(int, input().split()))
		if seg[0] <= k and k <= seg[1]:
			mid += 1
			if seg[0] <= k - 1:
				left += 1
			if seg[1] >= k + 1:
				right += 1
	if left == mid or right == mid:
		print('NO')
	else:
		print('YES')
t = int(input())
for _ in range(t):
	solution()


t = int(input())
for i_ in range(t):
	(n, k) = map(int, input().split())
	c1 = 0
	c2 = 0
	for j in range(n):
		(l, r) = map(int, input().split())
		if l == k:
			c1 += 1
		if r == k:
			c2 += 1
	if c1 != 0 and c2 != 0:
		print('YES')
	else:
		print('NO')


try:
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		arr = []
		t1 = 0
		t2 = 0
		for i in range(n):
			(x1, x2) = map(int, input().split())
			if x1 == k:
				t1 = 1
			if x2 == k:
				t2 = 1
			if x1 == k or x2 == k:
				arr.append([x1, x2])
		if t1 & t2:
			print('YES')
		else:
			print('NO')
except Exception as e:
	print(e)


for ((n, k), l0, r0) in ((map(int, input().split()), 0, 0) for _ in range(int(input()))):
	for (l, r) in (map(int, input().split()) for _ in range(n)):
		l0 |= l == k
		r0 |= r == k
	print(['NO', 'YES'][l0 and r0])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	min = -1
	max = -1
	flag = 0
	for _ in range(n):
		(x, y) = map(int, input().split(' '))
		if k >= x and k <= y:
			if min == -1 and max == -1:
				min = x
				max = y
			elif min < x:
				min = x
				if max > y:
					max = y
			elif max > y:
				max = y
			if min == k and max == k:
				flag = 1
	if flag == 0:
		print('NO')
	else:
		print('YES')


tc = int(input())
for _ in range(tc):
	(n, k) = map(int, input().split())
	segs = []
	for v in range(n):
		(l, r) = map(int, input().split())
		segs.append([l, r])
	count_l = 0
	count_r = 0
	for i in segs:
		if i == [k, k]:
			count_l += 1
			count_r += 1
			break
		elif i[0] == k:
			count_l += 1
		elif i[1] == k:
			count_r += 1
	if count_l >= 1 and count_r >= 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	b = []
	for _ in range(n):
		(l, r) = map(int, input().split())
		if l == m:
			a.append([l, r])
		if r == m:
			b.append([l, r])
	if a != [] and b != []:
		print('YES')
	else:
		print('NO')


def f():
	(n, k) = list(map(int, input().split()))
	begin = end = False
	for _ in range(n):
		(x1, x2) = list(map(int, input().split()))
		if x1 == k:
			begin = True
		if x2 == k:
			end = True
	if begin and end:
		print('YES')
	else:
		print('NO')
n = int(input())
for _ in range(n):
	f()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = y = 0
	l = [x, y]
	for i in range(n):
		(a, b) = map(int, input().split())
		if a == k:
			x = 1
		if b == k:
			y = 1
	if x & y:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, k) = map(int, input().split())
	t = 0
	tt = 0
	for i in range(n):
		(a, b) = map(int, input().split())
		if k == a:
			t = 1
		if b == k:
			tt = 1
	if t == 1 and tt == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	(start, end) = (False, False)
	for i in range(n):
		(x, y) = map(int, input().split())
		if x == k:
			start = True
		if y == k:
			end = True
	if start and end:
		print('YES')
	else:
		print('NO')


class EndPointl:

	def __init__(self, a, b) -> None:
		self.l = a
		self.r = b
count = int(input())
for _ in range(count):
	(n, k) = list(map(int, input().split()))
	start_cover = False
	end_cover = False
	for _ in range(n):
		(l, r) = list(map(int, input().split()))
		if l == k:
			start_cover = True
		if r == k:
			end_cover = True
	if start_cover and end_cover:
		print('YES')
	else:
		print('NO')


for tests in range(int(input())):
	(n, m) = map(int, input().split())
	(s, e) = (0, 0)
	for i in range(n):
		(l, r) = map(int, input().split())
		if l == m:
			s += 1
		if r == m:
			e += 1
	if s > 0 and e > 0:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	nk = [int(i) for i in input().split()]
	l = 0
	r = 0
	for i in range(nk[0]):
		lr = [int(i) for i in input().split()]
		if lr[0] == nk[1]:
			l += 1
		if lr[1] == nk[1]:
			r += 1
	if r >= 1 and l >= 1:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
while t != 0:
	(s, e) = map(int, input().split())
	l1 = []
	l2 = []
	f1 = 0
	f2 = 0
	for i in range(s):
		(n1, n2) = map(int, input().split())
		l1.append(n1)
		l2.append(n2)
	for i in l1:
		if i == e:
			f1 += 1
	for j in l2:
		if j == e:
			f2 += 1
	if f1 >= 1 and f2 >= 1:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = 0
	y = 0
	Nb = 0
	for i in range(n):
		(a, b) = map(int, input().split())
		if a <= k <= b:
			Nb += 1
			if not x and (not y):
				if a == k:
					x = a
				if b == k:
					y = b
			elif x and (not y) and (b == k):
				y = k
			elif y and (not x) and (a == k):
				x = a
	if x == y and x:
		print('YES')
	else:
		print('NO')