Every year Santa Claus gives gifts to all children. However, each country has its own traditions, and this process takes place in different ways. For example, in Berland you need to solve the New Year's puzzle.

Polycarp got the following problem: given a grid strip of size $2 \times n$, some cells of it are blocked. You need to check if it is possible to tile all free cells using the $2 \times 1$ and $1 \times 2$ tiles (dominoes).

For example, if $n = 5$ and the strip looks like this (black cells are blocked):

Then it can be tiled, for example, using two vertical and two horizontal tiles, as in the picture below (different tiles are marked by different colors).

And if $n = 3$ and the strip looks like this:

It is impossible to tile free cells.

Polycarp easily solved this task and received his New Year's gift. Can you solve it?


-----Input-----

The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. Then $t$ test cases follow.

Each test case is preceded by an empty line.

The first line of each test case contains two integers $n$ and $m$ ($1 \le n \le 10^9$, $1 \le m \le 2 \cdot 10^5$) — the length of the strip and the number of blocked cells on it.

Each of the next $m$ lines contains two integers $r_i, c_i$ ($1 \le r_i \le 2, 1 \le c_i \le n$) — numbers of rows and columns of blocked cells. It is guaranteed that all blocked cells are different, i.e. $(r_i, c_i) \ne (r_j, c_j), i \ne j$.

It is guaranteed that the sum of $m$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print on a separate line:

"YES", if it is possible to tile all unblocked squares with the $2 \times 1$ and $1 \times 2$ tiles;

"NO" otherwise.

You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).


-----Examples-----

Input
3

5 2
2 2
1 4

3 2
2 1
2 3

6 4
2 1
2 3
2 4
2 6
Output
YES
NO
NO


-----Note-----

The first two test cases are explained in the statement.

In the third test case the strip looks like this:

It is easy to check that the unblocked squares on it can not be tiled.

Difficulty: HARD
Tags: Sorting

Greedy algorithms

Complete search

Dynamic programming

Flows and cuts
Skill types: Dynamic programming

Sorting

Complete search

Greedy algorithms

Starter code:

Solutions:
import sys, os, io
import bisect
for _ in range(int(input())):
	input()
	(n, m) = [int(i) for i in input().split()]
	u = []
	d = []
	a = []
	for i in range(m):
		(x, y) = [int(i) for i in input().split()]
		a.append([y, x])
	a.sort()
	temp = 0
	flag = 0
	prev = 0
	previ = 0
	if m % 2 == 1:
		print('NO')
	else:
		for i in range(len(a)):
			if temp == 0:
				prev = a[i][0]
				previ = a[i][1]
				temp = 1
			else:
				if i != len(a) - 1:
					if a[i][0] == a[i + 1][0]:
						flag = 1
						break
				if previ == a[i][1]:
					if (a[i][0] - prev) % 2 == 0:
						flag = 1
						break
					else:
						temp = 0
				elif (a[i][0] - prev) % 2 == 1:
					flag = 1
					break
				else:
					temp = 0
		if flag:
			print('NO')
		else:
			print('YES')


t = int(input())
for _ in range(t):
	a = input()
	(n, m) = map(int, input().split())
	block = []
	for i in range(m):
		(a, b) = map(int, input().split())
		block.append((b, a))
	block.sort()

	def no():
		print('NO')

	def yes():
		print('YES')

	def main():
		flag = 0
		ne = 0
		last = 0
		while ne < m:
			if ne + 1 < m and block[ne][0] == block[ne + 1][0]:
				if flag == 0:
					last = block[ne][0]
					ne += 2
					continue
				else:
					return no()
			cur = block[ne][0]
			if flag == 0:
				flag = block[ne][1]
			elif block[ne][1] != flag:
				if (cur - last) % 2:
					return no()
				else:
					flag = 0
			elif (cur - last) % 2:
				flag = 0
			else:
				return no()
			last = block[ne][0]
			ne += 1
		if flag == 0:
			return yes()
		else:
			return no()
	main()


def solve():
	input()
	(n, m) = map(int, input().split())
	dudes = []
	for i in range(m):
		(r, c) = map(int, input().split())
		dudes.append((c, r))
	dudes.sort()
	dudes.reverse()
	cells = []
	while dudes:
		if not cells or cells[-1][0] != dudes[-1][0]:
			cells.append(dudes[-1])
		else:
			cells[-1] = (cells[-1][0], 3)
		dudes.pop()
	i = 0
	while i < len(cells):
		(ci, ri) = cells[i]
		if ri != 3:
			if i + 1 == len(cells):
				return False
			(cn, rn) = cells[i + 1]
			if rn == 3:
				return False
			i += 1
			if (ci ^ cn ^ ri ^ rn) & 1 == 0:
				return False
		i += 1
	return True
for _ in range(int(input())):
	print('YES' if solve() else 'NO')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):

	def __init__(self, file):
		self.newlines = 0
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

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

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

def N():
	return int(input())

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

def print_list(l):
	print(' '.join(map(str, l)))
from collections import Counter
for i in range(N()):
	input()
	(n, m) = RL()
	p = [tuple(RL()) for _ in range(m)]
	if m & 1:
		print('NO')
		continue
	dic = Counter()
	for (r, c) in p:
		dic[c] |= r
	x = sorted(list(dic.keys()))
	now = 0
	f = True
	for i in range(len(x)):
		if now == 0:
			now = 0 if dic[x[i]] == 3 else dic[x[i]]
		else:
			(a, b) = (dic[x[i - 1]], dic[x[i]])
			if b == 3 or (x[i] - x[i - 1] & 1 and a != b) or (x[i] - x[i - 1] & 1 == 0 and a == b):
				f = False
				break
			now = 0
	print('YES' if f else 'NO')


for _ in range(int(input())):
	input()
	(n, m) = map(int, input().split())
	a = []
	flag = 'YES'
	for _ in range(m):
		(b, c) = map(int, input().split())
		a.append([c, b])
	if m % 2:
		print('NO')
		continue
	a.sort()
	for x in range(0, m, 2):
		if a[x][1] == a[x + 1][1]:
			if (a[x + 1][0] - a[x][0]) % 2 == 0:
				flag = 'NO'
				break
		elif (a[x + 1][0] - a[x][0]) % 2 == 1:
			flag = 'NO'
			break
		if x != 0 and a[x - 1][0] == a[x][0]:
			flag = 'NO'
			break
	print(flag)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	input()
	(n, m) = map(int, input().split())
	a = []
	flag = 'YES'
	for _ in range(m):
		(b, c) = map(int, input().split())
		a.append([c, b])
	if m % 2:
		print('NO')
		continue
	a.sort()
	for x in range(0, m, 2):
		if a[x][1] == a[x + 1][1]:
			if (a[x + 1][0] - a[x][0]) % 2 == 0:
				flag = 'NO'
				break
		elif (a[x + 1][0] - a[x][0]) % 2 == 1:
			flag = 'NO'
			break
		if x != 0 and a[x - 1][0] == a[x][0]:
			flag = 'NO'
			break
	print(flag)


ans = []

def read():
	return int(input())

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

def readmore():
	return map(int, input().split())
x_test = 1
if x_test == 0:
	x_test = 1
else:
	x_test = int(input())
for _ in range(x_test):
	emptyline = input()
	(n, m) = readmore()
	if m % 2:
		print('NO')
		for i in range(m):
			input()
		continue
	L = []
	for i in range(m):
		(y, x) = readmore()
		L.append([x, y])
	L.sort()
	result = 'YES'
	k = 1
	for i in range(1, m):
		if k == 0:
			k = 1
			continue
		dx = L[i][0] - L[i - 1][0]
		dy = L[i][1] - L[i - 1][1]
		c1 = dx % 2
		c2 = dy % 2
		if c1 ^ c2:
			if i + 1 < m and L[i + 1][0] == L[i][0]:
				result = 'NO'
				break
			k = 0
		else:
			result = 'NO'
			break
	if k:
		result = 'NO'
	print(result)
ans = str(ans)
lls = len(ans)
_ans = ans[1:lls - 1].replace(', ', '\n')
print(_ans)


from collections import defaultdict, deque
import sys
import bisect
import math
input = sys.stdin.readline
mod = 1000000007
t = int(input())
for ii in range(t):
	input()
	(n, m) = map(int, input().split())
	coord = []
	for i in range(m):
		(x, y) = map(int, input().split())
		coord.append([y, x])
	coord.sort()
	if len(coord) & 1:
		print('NO')
	else:
		for i in range(0, m, 2):
			if coord[i][1] == coord[i + 1][1]:
				if (coord[i + 1][0] - coord[i][0]) % 2 == 0:
					print('NO')
					break
			elif (coord[i + 1][0] - coord[i][0]) % 2 == 1:
				print('NO')
				break
			if i != 0 and coord[i - 1][0] == coord[i][0]:
				print('NO')
				break
		else:
			print('YES')


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
inf = 10 ** 16
md = 10 ** 9 + 7
from collections import defaultdict

def ok():
	s = 0
	for (c, rr) in sorted(ctor.items()):
		r = rr[0]
		if s == 0:
			if len(rr) == 1:
				if (rr[0] == 1) ^ c & 1:
					s = 2
				else:
					s = 1
		elif s == 1:
			if len(rr) == 2:
				return False
			if c & 1 ^ (r == 2):
				return False
			s = 0
		elif s == 2:
			if len(rr) == 2:
				return False
			if c & 1 ^ (r == 1):
				return False
			s = 0
	return True
for _ in range(II()):
	SI()
	(n, m) = MI()
	ctor = defaultdict(list)
	for _ in range(m):
		(r, c) = MI()
		ctor[c].append(r)
	ctor[inf] = [1, 2]
	print('YES' if ok() else 'NO')


t = int(input())
for _ in range(t):
	input()
	(n, m) = [int(i) for i in input().split()]
	blocks = {}
	for _ in range(m):
		(r, c) = [int(i) for i in input().split()]
		if c in blocks:
			blocks[c] |= r
		else:
			blocks[c] = r
	li = sorted([list(i) for i in blocks.items()])
	leftover = 0
	for i in range(len(li)):
		conf = li[i][1]
		next_row_conf = 0
		if li[i][0] == 1:
			if conf == 1:
				next_row_conf = 2
			elif conf == 2:
				next_row_conf = 1
			elif conf == 3:
				next_row_conf = 0
		elif leftover == conf:
			next_row_conf = 0
		elif leftover == 0:
			if conf == 1:
				next_row_conf = 2
			elif conf == 2:
				next_row_conf = 1
			elif conf == 3:
				next_row_conf = 0
		elif leftover == 1:
			if conf == 0:
				next_row_conf = 1
			elif conf & 2:
				print('NO')
				break
		elif leftover == 2:
			if conf == 0:
				next_row_conf = 2
			elif conf & 1:
				print('NO')
				break
		elif conf == 0:
			next_row_conf = 0
		elif conf == 1:
			next_row_conf = 2
		elif conf == 2:
			next_row_conf = 1
		if i < len(li) - 1:
			if li[i + 1][0] - li[i][0] == 1:
				if next_row_conf & li[i + 1][1]:
					print('NO')
					break
				leftover = 3
				li[i + 1][1] |= next_row_conf
			else:
				parity = (li[i + 1][0] - li[i][0]) % 2
				if next_row_conf == 0:
					leftover = 3
				elif next_row_conf == 3:
					leftover = 0
				elif parity:
					leftover = 2 if next_row_conf == 1 else 1
				else:
					leftover = next_row_conf
	else:
		if next_row_conf != 0:
			print('NO')
		else:
			print('YES')


t = int(input())
for k in range(t):
	input()
	(n, m) = map(int, input().split(' '))
	arr = []
	num_dict = {}
	for i in range(m):
		(r, c) = map(int, input().split(' '))
		arr.append((c, r))
		num_dict[c] = num_dict.get(c, 0) + 1
	arr.sort()
	(cc, cr) = arr[0]
	cr = 3 - cr
	if num_dict[cc] == 1:
		imbalance = True
	else:
		imbalance = False
	is_valid = True
	for i in range(1, m):
		(c, r) = arr[i]
		if imbalance:
			if num_dict[c] == 2:
				is_valid = False
				break
			delta_c = c - cc
			if delta_c % 2:
				if r == cr:
					is_valid = False
					break
			elif r != cr:
				is_valid = False
				break
			imbalance = False
		else:
			cc = c
			cr = 3 - r
			if num_dict[c] == 1:
				imbalance = True
	if imbalance:
		is_valid = False
	if is_valid:
		print('YES')
	else:
		print('NO')


from itertools import groupby
t = int(input())
for _ in range(t):
	input()
	(n, m) = map(int, input().split())
	blocked = []
	for _ in range(m):
		(r, c) = map(int, input().split())
		blocked.append((c - 1, r - 1))
	blocked.extend([(n, 0), (n, 1)])
	blocked.sort()
	prev_blocked = None
	result = True
	for (c, it) in groupby(blocked, key=lambda t: t[0]):
		s = c % 2
		rs = [t[1] for t in it]
		if rs == [0, 1]:
			if prev_blocked is not None:
				result = False
				break
		elif rs == [0]:
			if prev_blocked is None:
				prev_blocked = s
			elif prev_blocked == s:
				result = False
				break
			else:
				prev_blocked = None
		elif prev_blocked is None:
			prev_blocked = s ^ 1
		elif prev_blocked == s ^ 1:
			result = False
			break
		else:
			prev_blocked = None
	if result:
		print('YES')
	else:
		print('NO')


from itertools import groupby

def solve():
	input()
	(n, m) = map(int, input().split())
	A = [[int(t) for t in input().split()] for _ in range(m)]
	A.sort(key=lambda p: p[1])
	(ps, pc) = (0, 0)
	for (c, it) in groupby(A, key=lambda p: p[1]):
		r = sum((p[0] for p in it))
		if ps == 0:
			cs = 0
		else:
			cs = ps if (c - pc) % 2 == 0 else 3 - ps
		if cs & r:
			print('NO')
			break
		cs |= r
		if cs == 3:
			cs = 0
		(ps, pc) = (cs, c)
	else:
		print('YES' if cs == 0 else 'NO')
import sys, os, io
input = sys.stdin.readline
stdout = io.BytesIO()
sys.stdout.write = lambda s: stdout.write(s.encode('ascii'))
for _ in range(int(input())):
	solve()
os.write(1, stdout.getvalue())


t = int(input())
while t > 0:
	t -= 1
	space = input()
	(n, m) = [int(x) for x in input().split()]
	blocked = [[0, 0]]
	for i in range(m):
		blocked.append([int(x) for x in input().split()])
	blocked.sort(key=lambda x: x[1])
	gap = [0]
	for i in range(1, m + 1):
		g = blocked[i][1] - blocked[i - 1][1] - 1
		sign = 1
		if g < 0:
			sign = -1
		gap.append(g % 2 * sign)
	curr = 0
	for i in range(1, m + 1):
		curr += gap[i] + 1
		blocked[i][1] = curr
	n = blocked[-1][1]
	dp = [[0, 0] for x in range(n + 1)]
	possible = True
	for i in range(1, m + 1):
		(row, col) = (blocked[i][0] - 1, blocked[i][1])
		dp[col][row] += 1
	for i in range(1, n):
		if dp[i] == [0, 0]:
			if dp[i + 1] == [0, 0]:
				(dp[i], dp[i + 1]) = ([1, 1], [1, 1])
			else:
				dp[i] = [1, 1]
		elif dp[i] == [1, 0]:
			if dp[i + 1] == [0, 0]:
				(dp[i], dp[i + 1]) = ([1, 1], [0, 1])
			elif dp[i + 1] == [1, 0]:
				(dp[i], dp[i + 1]) = ([1, 1], [1, 1])
			else:
				possible = False
				break
		elif dp[i] == [0, 1]:
			if dp[i + 1] == [0, 0]:
				(dp[i], dp[i + 1]) = ([1, 1], [1, 0])
			elif dp[i + 1] == [0, 1]:
				(dp[i], dp[i + 1]) = ([1, 1], [1, 1])
			else:
				possible = False
				break
		else:
			pass
	if dp[-1] != [1, 1]:
		possible = False
	if possible == True:
		print('yes')
	else:
		print('no')


import sys
input = sys.stdin.readline
from collections import defaultdict
import bisect
for _ in range(int(input())):
	blank = input()
	(n, m) = map(int, input().split())
	A = defaultdict(int)
	for _ in range(m):
		(a, b) = map(int, input().split())
		a -= 1
		A[b] |= 1 << a
	if m % 2:
		print('NO')
		continue
	last = 0
	status = 3
	for a in sorted(A):
		b = A[a]
		if last == 0:
			last = a
			status = b
		elif b == 1 and status == 1:
			if not (a - last) % 2:
				print('NO')
				break
			else:
				status = 3
				last = a
		elif b == 2 and status == 2:
			if not (a - last) % 2:
				print('NO')
				break
			else:
				status = 3
				last = a
		elif b == 3 and status != 3:
			print('NO')
			break
		elif b == 1 and status == 2 or (b == 2 and status == 1):
			if (a - last) % 2:
				print('NO')
				break
			else:
				status = 3
				last = a
		elif b in [1, 2] and status == 3:
			last = a
			status = b
		else:
			last = a
			status = b
	else:
		print('YES' if status == 3 else 'NO')


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def main():
	for _ in range(int(input())):
		input()
		(n, m) = map(int, input().split())
		a = defaultdict(list)
		for i in range(m):
			(x, y) = map(int, input().split())
			a[y].append(x - 1)
		(lc, lr, ans) = (-1, -1, 'YES')
		for i in sorted(a.keys()):
			if lc == -1:
				if len(a[i]) != 2:
					lc = i
					lr = a[i][0]
			else:
				if (i - lc) % 2:
					lr ^= 1
				if lr in a[i]:
					break
				lc = -1
		if lc != -1:
			ans = 'NO'
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	input()
	(n, m) = map(int, input().split())
	mask = defaultdict(int)
	for _ in range(m):
		(r, c) = map(int, input().split())
		mask[c] += 1 << r - 1
	mask[n + 1] = 3
	ks = list(mask.keys())
	ks.sort()
	last_row = -1
	flag = True
	for i in range(len(ks)):
		if mask[ks[i]] == 3:
			if last_row != -1:
				flag = False
		elif last_row == -1:
			if mask[ks[i]] == 1:
				last_row = 1
			else:
				last_row = 0
		else:
			r = (ks[i] - ks[i - 1] - 1 + last_row) % 2
			if mask[ks[i]] >> r & 1:
				flag = False
			last_row = -1
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	space = input()
	(n, m) = map(int, input().split())
	block = []
	for i in range(m):
		block.append(list(map(int, input().split())))
	block.sort(key=lambda x: x[1])
	before = -1
	if m % 2 != 0:
		print('NO')
		continue
	for ind in range(m):
		(i, j) = block[ind]
		if ind < m - 1:
			if before != -1 and block[ind][1] == block[ind + 1][1]:
				break
		if before == -1:
			before = (i + j) % 2
		elif (i + j) % 2 == 1 - before:
			before = -1
		else:
			break
	if before == -1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	input()
	(n, m) = map(int, input().split())
	a = []
	f = 1
	for i in range(m):
		(x, y) = map(int, input().split())
		a.append([y, x])
	if m % 2:
		print('NO')
		continue
	a.sort()
	for i in range(0, m, 2):
		if a[i][1] == a[i + 1][1]:
			if (a[i + 1][0] - a[i][0]) % 2 == 0:
				f = 0
				break
		elif (a[i + 1][0] - a[i][0]) % 2 == 1:
			f = 0
			break
		if i != 0 and a[i - 1][0] == a[i][0]:
			f = 0
			break
	if f == 1:
		print('YES')
	else:
		print('NO')


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	input()
	(n, m) = map(int, input().split())
	blocks = [[0, 1], [0, 2], [n + 1, 1], [n + 1, 2]]
	for i in range(m):
		(r, c) = map(int, input().split())
		blocks.append([c, r])
	blocks.sort()
	pointer = 0
	lastone = 0
	lasttwo = 0
	flag = 0
	for i in range(2, len(blocks)):
		c = blocks[i][0]
		r = blocks[i][1]
		if r == 1:
			if (c - lastone) % 2 == 0:
				if lasttwo == c or (c - 1 - lasttwo) % 2 == 0:
					flag = 1
					break
				lasttwo = c - 1
			lastone = c
		else:
			if (c - lasttwo) % 2 == 0:
				if lastone == c or (c - 1 - lastone) % 2 == 0:
					flag = 1
					break
				lastone = c - 1
			lasttwo = c
	if flag == 1:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	input()
	(n, m) = map(int, input().split())
	l = []
	for _ in range(m):
		(r, c) = map(int, input().split())
		l.append((r, c))
	l.sort(key=lambda x: (x[1], x[0]))
	if m & 1:
		print('NO')
		continue
	for i in range(0, m, 2):
		(r, c) = (l[i][0], l[i][1])
		(nr, nc) = (l[i + 1][0], l[i + 1][1])
		if r == nr:
			if (nc - c) % 2 == 0:
				print('NO')
				break
		elif (nc - c) % 2 == 1:
			print('NO')
			break
		if i != 0 and l[i - 1][1] == c:
			print('NO')
			break
	else:
		print('YES')
	l


import sys
input = sys.stdin.readline
from operator import itemgetter
t = int(input())
for tests in range(t):
	_ = input().strip()
	(n, m) = map(int, input().split())
	B = [tuple(map(int, input().split())) for i in range(m)]
	if len(B) % 2 != 0:
		print('NO')
		continue
	D = dict()
	for (x, y) in B:
		if y in D:
			D[y].append(x)
		else:
			D[y] = [x]
	L = sorted(D)
	now = -1
	for l in L:
		if now == -1:
			if len(D[l]) == 2:
				continue
			elif D[l] == [2]:
				now = (0 + l) % 2
			else:
				now = (1 + l) % 2
		elif len(D[l]) == 2:
			print('NO')
			break
		else:
			k = (l + D[l][0]) % 2
			if k != now:
				now = -1
			else:
				print('NO')
				break
	else:
		print('YES')


z = input
w = lambda : map(int, z().split())
for _ in [8] * int(z()):
	z()
	(_, m) = w()
	d = l = 0
	for (x, y) in sorted(([*w()][::-1] for _ in [8] * m)):
		d += (x + y) % 2 * 2 - 1
		if abs(d) > 1 or (l == x and d):
			d = m
		l = x
	print('no' if d else 'yes')


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	input()
	(n, b) = map(int, input().split())
	ans = 'YES'
	a = []
	s = set()
	for i in range(b):
		(x, y) = map(int, input().split())
		a.append([y, x])
		s.add((x, y))
	if b % 2:
		ans = 'NO'
	else:
		a.sort()
		i = 0
		while i < b and ans == 'YES':
			(y1, x1) = a[i]
			(y2, x2) = a[i + 1]
			i += 2
			if x1 == x2:
				if (y2 - y1 - 1) % 2 or (x1 == 1 and (2, y2) in s):
					ans = 'NO'
			else:
				if y1 == y2:
					continue
				if not (y2 - y1 - 1) % 2 or (x2 == 1 and (2, y2) in s):
					ans = 'NO'
	print(ans)


from sys import stdin, stdout

def input():
	return stdin.readline().strip()

def split_pred(arr, pred):
	ret = []
	lazy = []
	for a in arr:
		if pred(a):
			if len(lazy):
				ret += [lazy]
			lazy = []
		else:
			lazy += [a]
	if len(lazy):
		ret += [lazy]
	return ret

def colour(r, c):
	r %= 2
	c %= 2
	if r == c:
		return 1
	else:
		return -1

def ok(run):
	if len(run) == 0:
		return True
	(c0, r0) = min(run)
	run = [(c - c0, r) for (c, r) in run]
	if len(run) % 2 == 1:
		return False
	for i in range(len(run) // 2):
		(x, y) = run[2 * i]
		(xx, yy) = run[2 * i + 1]
		sc = colour(x, y) + colour(xx, yy)
		if sc != 0:
			return False
	return True

def ans(N, blocked):
	blocked_top = []
	blocked_bottom = []
	for (r, c) in blocked:
		if r == 1:
			blocked_top += [c]
		else:
			blocked_bottom += [c]
	pillars = set(blocked_top) & set(blocked_bottom)
	blocked = sorted([(c, r) for (r, c) in blocked])
	blocked = split_pred(blocked, lambda cr: cr[0] in pillars)
	for run in blocked:
		if not ok(run):
			return 'NO'
	return 'YES'
for _ in range(int(input())):
	input()
	[N, M] = list(map(int, input().split()))
	blocked = []
	for _ in range(M):
		[x, y] = list(map(int, input().split()))
		x -= 1
		y -= 1
		blocked += [(x, y)]
	print(ans(N, blocked))


import sys

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

def mint():
	return int(input())

def mints():
	return map(int, input().split())
for t in range(mint()):
	input()
	(n, m) = mints()
	a = [None] * m
	for i in range(m):
		(r, c) = mints()
		a[i] = (c, r - 1)
	a.sort()
	b = []
	i = 0
	while i < m:
		(c, r) = a[i]
		i += 1
		x = 1 << r
		if i < m and a[i][0] == c:
			x |= 1 << a[i][1]
			i += 1
		b.append((c, x))
	bad = False
	while len(b) > 0:
		(c, p) = b[-1]
		if p == 3:
			b.pop()
		elif len(b) < 2 or b[-2][1] != p ^ (c - b[-2][0] + 1) % 2 * 3:
			bad = True
			break
		else:
			b.pop()
			b.pop()
	if bad:
		print('NO')
	else:
		print('YES')


try:
	t = int(input())
	for _ in range(t):
		input()
		(n, m) = [int(i) for i in input().split()]
		if m % 2 == 1:
			for iii in range(m):
				input()
			print('NO')
			continue
		block = {}
		ind = []
		for iii in range(m):
			(a, b) = [int(i) - 1 for i in input().split()]
			ind.append(b)
			if b in block:
				block[b] = 'b'
			elif a == 0:
				block[b] = 'u'
			else:
				block[b] = 'd'
		ind.sort()
		sit = 'b'
		(prei, pind) = (-1, -1)
		for i in ind:
			if prei == i:
				continue
			if sit + block[i] == 'bb':
				continue
			elif sit + block[i] in ('uu', 'dd'):
				if (i - pind) % 2 == 1:
					print('NO')
					break
				else:
					sit = 'b'
			elif sit + block[i] in ('ud', 'du'):
				if (i - pind) % 2 == 0:
					print('NO')
					break
				else:
					sit = 'b'
			elif sit + block[i] == 'bd':
				sit = 'u'
			elif sit + block[i] == 'bu':
				sit = 'd'
			elif sit + block[i] in ('ub', 'db'):
				print('NO')
				break
			(pind, prei) = (i, i)
		else:
			if sit == 'b':
				print('YES')
			else:
				print('NO')
except Exception as e:
	print(e)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations, combinations

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
sys.setrecursionlimit(100000)
INF = float('inf')
mod = 10 ** 9 + 7
for t in range(int(data())):
	data()
	(n, m) = mdata()
	M = [mdata() for i in range(m)]
	M.sort(key=lambda x: (x[1], x[0]))
	if m % 2:
		out('NO')
	else:
		ans = 'YES'
		for i in range(0, m, 2):
			if (M[i][0] + M[i + 1][0] + M[i][1] + M[i + 1][1]) % 2 == 0 or (i + 2 < m and M[i + 1][1] == M[i + 2][1]):
				ans = 'NO'
				break
		out(ans)


import operator

def partion_check(B) -> bool:
	location = 0
	row = 1
	current_row = None
	active_block = None
	for (index, block) in enumerate(B):
		if not active_block:
			active_block = block
			continue
		if active_block:
			if active_block[row] + 1 == block:
				return False
			if active_block[location] == block[location]:
				if (block[row] - active_block[row]) % 2 != 1:
					return False
			elif (block[row] - active_block[row]) % 2 != 0:
				return False
			active_block = None
	return not active_block

def solve(A) -> bool:
	A.sort(key=operator.itemgetter(1))
	B = []
	for block in A:
		if not B:
			B.append(block)
			continue
		last_block = B[-1]
		if last_block[1] == block[1]:
			B.pop()
			if not partion_check(B):
				return False
			B = []
			continue
		B.append(block)
	return partion_check(B)
t = int(input())
while t:
	empty_line = input()
	(_m, n) = map(int, input().split())
	all_blocks = []
	while n:
		all_blocks.append(tuple(map(int, input().split())))
		n -= 1
	print('YES') if solve(all_blocks) else print('NO')
	t -= 1


def puzzle(allPoint):
	n = len(allPoint)
	if n % 2 == 1:
		return 'NO'
	allPoint.sort()
	while allPoint:
		(l1, r1) = allPoint.pop()
		(l2, r2) = allPoint.pop()
		if l1 == l2:
			continue
		if (l1 + r1) % 2 == (l2 + r2) % 2:
			return 'NO'
		if allPoint and l2 == allPoint[-1][0]:
			return 'NO'
	return 'YES'
t = int(input())
for qwq in range(t):
	input()
	ll = list(map(int, input().split()))
	allPoint = []
	for i in range(ll[1]):
		cin = list(map(int, input().split()))
		allPoint.append((cin[1], cin[0]))
	print(puzzle(allPoint))


in_length = int(input())
final_ouput = []
for i in range(in_length):
	blank = input()
	[length, num_obstructions] = input().split()
	state_saver = dict()
	h_positon_obstacles = []
	for j in range(int(num_obstructions)):
		[row, column] = input().split()
		col_index = int(column) - 1
		if not col_index in state_saver:
			state_saver.update({col_index: row})
		else:
			state_saver.update({col_index: state_saver[col_index] + row})
		h_positon_obstacles.append(col_index)
	final_ouput.append('YES')
	if len(h_positon_obstacles) % 2 != 0:
		final_ouput[i] = 'NO'
		continue
	h_positon_obstacles = sorted(h_positon_obstacles)
	for j in range(0, len(h_positon_obstacles), 2):
		block1 = h_positon_obstacles[j]
		block2 = h_positon_obstacles[j + 1]
		if block1 == block2:
			continue
		col_block1 = state_saver[block1]
		col_block2 = state_saver[block2]
		if len(col_block1) == len(col_block2):
			separation_parity = (block2 - block1 - 1) % 2
			if col_block1 != col_block2 and separation_parity == 0:
				final_ouput[i] = 'NO'
				break
			elif col_block1 == col_block2 and separation_parity != 0:
				final_ouput[i] = 'NO'
				break
		else:
			final_ouput[i] = 'NO'
			break
for out in final_ouput:
	print(out)


for nt in range(int(input())):
	input()
	(n, m) = map(int, input().split())
	block = []
	for i in range(m):
		(x, y) = map(int, input().split())
		block.append([y - 1, x - 1])
	block.sort()
	ans = 'YES'
	if m % 2:
		ans = 'NO'
		print(ans)
		continue
	for i in range(0, m, 2):
		(r, c) = (block[i][1], block[i][0])
		(r1, c1) = (block[i + 1][1], block[i + 1][0])
		if r == r1:
			if (c1 - c) % 2 == 0:
				ans = 'NO'
				break
		elif (c1 - c) % 2:
			ans = 'NO'
			break
		if i != 0 and block[i - 1][0] == c:
			ans = 'NO'
			break
	print(ans)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm, zip_longest
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	s = data()
	(n, m) = sp()
	d = C()
	for i in range(m):
		(r, c) = sp()
		d[c] |= 1 << r - 1
	result = True
	s = pos = 0
	for (a, b) in sorted(d.items(), key=lambda x: x[0]):
		if s in [0, 3]:
			if b == 3:
				continue
			s = b
			pos = a
			continue
		if b == 3:
			result = False
			break
		if s == 1:
			if b == 1 and (not a - pos & 1):
				result = False
				break
			if b == 2 and a - pos & 1:
				result = False
				break
			s = 0
			pos = a
			continue
		if b == 1 and a - pos & 1:
			result = False
			break
		if b == 2 and (not a - pos & 1):
			result = False
			break
		s = 0
		pos = a
	if s in [1, 2]:
		result = False
	out(('No', 'Yes')[result])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	input()
	(n, m) = map(int, input().split())
	a = [tuple(map(int, input().split())) for _ in range(m)]
	a.sort(key=lambda x: x[1])
	l = [0, 0]
	for (r, x) in a:
		r -= 1
		if (x - l[r] - 1) % 2 == 0:
			l[r] = x
		elif x - l[r ^ 1] >= 2 and (x - l[r ^ 1] - 2) % 2 == 0:
			l[r] = x
			l[r ^ 1] = x - 1
		else:
			print('NO')
			break
	else:
		print('YES' if l[0] % 2 == l[1] % 2 else 'NO')


t = int(input())
for _ in range(t):
	input()
	(n, m) = map(int, input().split())
	arr = []
	for i in range(m):
		(a, b) = map(int, input().split())
		arr.append([b, a])
	if m % 2 == 1:
		print('NO')
	else:
		black = 0
		white = 0
		su = []
		for i in arr:
			if (i[0] + i[1]) % 2 == 0:
				black = black + 1
			else:
				white = white + 1
			su.append(i[0] + i[1])
		if black != white:
			print('NO')
		else:
			sta = []
			su.sort()
			boo = True
			for i in range(len(su)):
				if len(sta) == 0:
					sta.append(su[i])
				elif abs(sta[0] - su[i]) % 2 == 1:
					sta.pop()
				else:
					boo = False
					break
			if boo == False:
				print('NO')
			else:
				jj = []
				arr.sort()
				cnt = 0
				for i in arr:
					cnt = cnt + 1
					if len(jj) == 0:
						jj.append(i[0])
					elif jj[0] != i[0]:
						jj.pop()
						jj.append(i[0])
					elif cnt % 2 == 1:
						boo = False
						break
				if boo == False:
					print('NO')
				else:
					print('YES')


from collections import defaultdict
t = int(input())
for _ in range(t):
	input()
	(n, m) = map(int, input().split())
	blocked = defaultdict(lambda : [])
	for i in range(m):
		(r, c) = map(int, input().split())
		blocked[c].append(r)
	if m % 2 == 1:
		print('NO')
		continue
	else:
		blocked = {k: v for (k, v) in sorted(blocked.items(), key=lambda item: item[0], reverse=False)}
		numbered = {k: v for (k, v) in enumerate(blocked)}
		flag = True
		chk = True
		checked = set()
		for (index, row) in numbered.items():
			if index in checked:
				continue
			if flag:
				if len(blocked[row]) == 2:
					checked.add(index)
					continue
				flag = False
			next_row = numbered[index + 1]
			empty = next_row - row - 1
			if empty % 2 == 0:
				if len(blocked[next_row]) == 2:
					print('NO')
					chk = False
					break
				elif blocked[next_row] != blocked[row]:
					print('NO')
					chk = False
					break
			elif len(blocked[next_row]) == 2:
				print('NO')
				chk = False
				break
			elif blocked[next_row] == blocked[row]:
				print('NO')
				chk = False
				break
			flag = True
			checked.add(index)
			checked.add(index + 1)
		if chk:
			print('YES')


def solve():
	tech = input()
	(n, m) = [int(i) for i in input().split()]
	s = set()
	for i in range(m):
		(r, c) = [int(i) for i in input().split()]
		s.add((r, c))
	full = set()
	tmp = set()
	for item in s:
		if item[1] in tmp:
			full.add(item[1])
		else:
			tmp.add(item[1])
	a = list(sorted(s, key=lambda x: (x[1], x[0])))
	if len(a) % 2 == 1:
		print('NO')
		return
	for i in range(0, len(a) - 1, 2):
		if a[i][1] in full:
			continue
		if a[i + 1][1] in full:
			print('NO')
			return
		if a[i][0] == a[i + 1][0]:
			if abs(a[i][1] - a[i + 1][1]) % 2 == 0:
				print('NO')
				return
		elif abs(a[i][1] - a[i + 1][1]) % 2 == 1:
			print('NO')
			return
	print('YES')
	return
for t in range(int(input())):
	solve()


for _ in range(int(input())):
	non = input()
	(n, m) = map(int, input().split())
	blocks = []
	for b in range(m):
		(x, y) = map(int, input().split())
		blocks.append((x, y))
	if m % 2 == 1:
		print('NO')
		continue
	blocks.sort(key=lambda x: x[1])
	i = 0
	while i < m - 1:
		(block1, block2, block3) = (blocks[i], blocks[i + 1], (0, -1))
		if i < m - 2:
			block3 = blocks[i + 2]
		if block1[1] == block2[1]:
			i += 2
			continue
		elif block2[1] == block3[1]:
			print('NO')
			break
		if block1[0] == block2[0]:
			if (block2[1] - block1[1]) % 2 == 0:
				print('NO')
				break
			else:
				i += 2
				continue
		elif (block2[1] - block1[1]) % 2 == 1:
			print('NO')
			break
		else:
			i += 2
			continue
	if i >= m:
		print('YES')


import bisect
import sys
data = sys.stdin.read().split('\n')[::-1]

def input():
	return data.pop()

def solve(strip, n):
	if n == 1:
		return strip.get(0, 0) in (0, 3)
	strip[n] = 3
	keys = sorted(strip)
	dp_prev = [0] * 4
	dp_prev[strip.get(0, 0)] = 1
	i = 1
	while i <= n:
		if i not in strip:
			j = keys[bisect.bisect_right(keys, i)]
			i = max(i, i + (j - i - 2) // 2 * 2)
		red = strip.get(i, 0)
		dp = [0] * 4
		if dp_prev[0] or dp_prev[3]:
			dp[red] = 1
		if dp_prev[1]:
			if red & 2 == 0:
				dp[red | 2] = 1
		if dp_prev[2]:
			if red & 1 == 0:
				dp[red | 1] = 1
		dp_prev = dp
		i += 1
	return dp_prev[3]
for _ in range(int(input())):
	_ = input()
	(n, m) = map(int, input().split())
	strip = {}
	for _ in range(m):
		(r, c) = map(int, input().split())
		r -= 1
		c -= 1
		strip.setdefault(c, 0)
		strip[c] |= 1 << r
	print('YES' if solve(strip, n) else 'NO')


from itertools import repeat, groupby
from operator import itemgetter as ig

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

def num():
	return int(input())

def nfunc(f, n, *args, **kwargs):
	return (f(*args, **kwargs) for _ in repeat(None, n))
t = num()
for _ in repeat(None, t):
	input()
	(n, m) = line()
	blocks = [(c, sum((r for (r, _) in q))) for (c, q) in groupby(sorted(((r, c) for (r, c) in nfunc(line, m)), key=ig(1)), key=ig(1))]
	q = 0
	i = 0
	for (c, w) in blocks:
		if q == 0:
			q = w % 3
			i = c
		elif w != 3 and (c - i) % 2 == (q == w):
			q = 0
		else:
			break
	else:
		if q == 0:
			print('YES')
			continue
	print('NO')


import io
import os
from collections import Counter, defaultdict, deque
from bisect import bisect_left

def solve(N, M, RC):
	if (2 * N - M) % 2 != 0:
		return 'NO'
	row0 = set()
	row1 = set()
	for (r, c) in RC:
		if r == 0:
			row0.add(c)
		else:
			assert r == 1
			row1.add(c)
	sortedCols = sorted(row0 | row1 | {0, N - 1})
	prevC = {}
	for (c1, c2) in zip(sortedCols, sortedCols[1:]):
		prevC[c2] = c1
	cache = [{} for i in range(4)]

	def dp(pattern, c):
		if c not in cache[pattern]:
			must = (c in row0) << 1 | (c in row1)
			if pattern & must != must:
				ret = 0
			else:
				need = pattern ^ must
				if need == 0 or need == 3:
					if c == 0:
						ret = 1
					else:
						ret = dp(3, prevC[c])
				elif c == 0:
					ret = 0
				else:
					c2 = prevC[c]
					if (c - c2) % 2:
						ret = dp(3 ^ need, c2)
					else:
						ret = dp(need, c2)
			cache[pattern][c] = ret
		return cache[pattern][c]
	for c in sortedCols:
		for pattern in range(4):
			dp(pattern, c)
	if dp(3, N - 1):
		return 'YES'
	else:
		return 'NO'
DEBUG = False
if DEBUG:
	import random
	random.seed(0)
	for _ in range(100):
		N = random.randint(1, 10)
		grid = [[random.randint(0, 1) for i in range(N)], [random.randint(0, 1) for i in range(N)]]
		RC = []
		for r in range(2):
			for c in range(N):
				if grid[r][c]:
					RC.append((r, c))
		print('tc', N, RC)
		ans1 = solve(N, len(RC), RC)
		print(ans1)
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	input()
	(N, M) = [int(x) for x in input().split()]
	RC = [[int(x) - 1 for x in input().split()] for i in range(M)]
	ans = solve(N, M, RC)
	print(ans)


import sys
from bisect import bisect_left
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	_ = input()
	(n, m) = map(int, input().split())
	cc = dict()
	for _ in range(m):
		(r, c) = map(int, input().split())
		if c in cc:
			cc[c] = 0
		else:
			cc[c] = r
	cc[n + 1] = 0
	(ok, p, ty) = (1, 0, 0)
	for (cp, cty) in sorted(cc.items()):
		ln = cp - p - 1
		if ty == 0:
			(p, ty) = (cp, cty)
		elif cty == 0:
			ok = 0
		elif ty == cty and ln % 2 == 0 or (ty != cty and ln % 2):
			(p, ty) = (cp, 0)
		else:
			ok = 0
		if not ok:
			break
	print('YES' if ok else 'NO')


import sys
input = sys.stdin.readline
from sys import stdin, stdout
from collections import defaultdict, Counter
M = 10 ** 9 + 7

def main():
	for _ in range(int(input())):
		s = input()
		(n, m) = [int(s) for s in input().split()]
		l = sorted([[int(s) for s in input().split()] for i in range(m)], key=lambda x: x[1])
		l1 = []
		prev = [l[0][1], l[0][0]]
		for i in range(1, m):
			if prev:
				if prev[0] == l[i][1]:
					prev[1] = 3
					l1.append(prev)
					prev = []
				else:
					l1.append(prev)
					prev = [l[i][1], l[i][0]]
			else:
				prev = [l[i][1], l[i][0]]
		if prev:
			l1.append(prev)
		curr = 0
		prev = 0
		flag = 0
		w = len(l1)
		for i in range(w):
			if l1[i][1] == 1:
				if curr == 0:
					curr = 2
					prev = l1[i][0]
				elif curr == 1:
					if l1[i][0] % 2 == (prev + 1) % 2:
						flag = 1
						break
					else:
						curr = 0
				elif l1[i][0] % 2 == (prev + 1) % 2:
					curr = 0
				else:
					flag = 1
					break
			elif l1[i][1] == 2:
				if curr == 0:
					curr = 1
					prev = l1[i][0]
				elif curr == 2:
					if l1[i][0] % 2 == (prev + 1) % 2:
						flag = 1
						break
					else:
						curr = 0
				elif l1[i][0] % 2 == (prev + 1) % 2:
					curr = 0
				else:
					flag = 1
					break
			elif curr != 0:
				flag = 1
				break
		if flag:
			print('NO')
		elif curr == 0:
			print('YES')
		else:
			print('NO')
main()


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve(t):
	s = si()
	(n, m) = mi()
	a = dd(int)
	s = set()
	for i in range(m):
		(x, y) = mi()
		a[y] |= 1 << x - 1
		s.add(y)
	s = list(s)
	s.sort()
	(r1, r2) = (0, 0)
	if a[s[0]] == 1:
		r2 = 1
	elif a[s[0]] == 2:
		r1 = 1
	for i in range(1, len(s)):
		gap = s[i] - s[i - 1]
		if gap % 2 == 0:
			(r1, r2) = (r2, r1)
		if (a[s[i]] == 1 or a[s[i]] == 3) and r1:
			return 'NO'
		if (a[s[i]] == 2 or a[s[i]] == 3) and r2:
			return 'NO'
		if r1:
			a[s[i]] ^= 1
		if r2:
			a[s[i]] ^= 2
		if a[s[i]] == 0 or a[s[i]] == 3:
			(r1, r2) = (0, 0)
		elif a[s[i]] == 1:
			r2 = 1
			r1 = 0
		else:
			r1 = 1
			r2 = 0
	if r1 == 1 or r2 == 1:
		return 'NO'
	else:
		return 'YES'
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
for t in range(ii()):
	print(solve(t))


from sys import stdin
t = int(stdin.readline())
for k in range(t):
	sp = stdin.readline()
	(n, m) = map(int, stdin.readline().split())
	l = []
	for i in range(m):
		(i, j) = map(int, stdin.readline().split())
		l.append((i, j))
	previ = -1
	prevj = -1
	solved = 0
	counter = 0
	for i in sorted(l, key=lambda x: (x[1], x[0])):
		if previ == -1 and prevj == -1:
			solved = i[0]
			(previ, prevj) = (i[0], i[1])
			continue
		if counter != 0:
			break
		if i[1] - prevj == 0:
			if solved == 1 and previ != i[0]:
				solved = 0
			else:
				counter = 4
				break
		elif i[1] - prevj == 1:
			if solved == 0:
				solved = i[0]
			elif solved == i[0]:
				solved = 0
			else:
				counter = 1
				break
		elif 3 - i[0] == solved:
			if (i[1] - prevj) % 2 == 0:
				solved = 0
			else:
				counter = 2
				break
		elif (i[1] - prevj) % 2 != 0 and solved == i[0]:
			solved = 0
		elif solved != 0:
			counter = 3
			break
		else:
			solved = i[0]
		(previ, prevj) = (i[0], i[1])
	if counter != 0 or solved != 0:
		print('NO')
	else:
		print('YES')


import sys
z = sys.stdin.readline
for _ in [8] * int(z()):
	z()
	(_, m) = map(int, z().split())
	d = l = 0
	c = [[*map(int, z().split())] for _ in range(m)]
	c.sort(key=lambda x: x[1])
	for (x, y) in c:
		d += (x + y) % 2 * 2 - 1
		if abs(d) > 1 or (l == y and d):
			d = m
		l = y
	else:
		print('no' if d else 'yes')


import sys, io, os
Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
o = []
for _ in range(int(Z())):
	Z()
	(n, m) = map(int, Z().split())
	p = [(0, 0), (0, 1)]
	for i in range(m):
		(r, c) = map(int, Z().split())
		r -= 1
		p.append((c, r))
	p.sort()
	p += [(n + 1, 0), (n + 1, 1)]
	v = -2
	i = 0
	while i < m + 4:
		b = p[i][0] == p[i + 1][0]
		p[i] = (v + 2 - (p[i][0] - v) % 2, p[i][1])
		i += 1
		if b:
			p[i] = (v + 2 - (p[i][0] - v) % 2, p[i][1])
			i += 1
		v = p[i - 1][0]
	x = [0] * (2 * p[-1][0] + 2)
	y = 1
	for i in p:
		x[2 * i[0] + i[1]] = 1
	for i in range(p[-1][0]):
		if x[2 * i] == 0:
			if x[2 * i + 1] < 1:
				continue
			if x[2 * i + 2]:
				y = 0
				break
			x[2 * i + 2] = 1
			continue
		if x[2 * i + 1] < 1:
			if x[2 * i + 3]:
				y = 0
				break
			x[2 * i + 3] = 1
	o.append(['NO', 'YES'][y])
print('\n'.join(o))


from collections import defaultdict

def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	input()
	(n, m) = read_ints()
	blocks = defaultdict(int)
	blocks[0] = 3
	blocks[n + 1] = 3
	for i in range(m):
		(r, c) = read_ints()
		blocks[c] += r
	keys = sorted(list(blocks.keys()))
	l = len(keys)
	black = 0
	white = 0
	singles = []
	valid = True

	def validate(singles):
		m = len(singles)
		for i in range(m):
			(l, r, c) = singles[i]
			if (r - l + 1) % 2 == 0:
				continue
			if i < m - 1:
				code = singles[i + 1][0] - r - 1 + (c + singles[i + 1][2])
				if code % 2 != 0:
					return False
				singles[i + 1][0] += 1
		return True
	for i in range(1, l):
		left = keys[i - 1]
		col = keys[i]
		if keys[i - 1] < col - 1:
			if blocks[col] == 3:
				if black != white:
					valid = False
					break
				if not validate(singles):
					valid = False
					break
				black = 0
				white = 0
				singles = []
			else:
				cell = blocks[col] + col
				if cell % 2 == 0:
					white += 1
				else:
					black += 1
				singles.append([col, col, blocks[col]])
		else:
			if blocks[left] == 3 or blocks[col] == 3 or blocks[col] + blocks[left] == 3:
				if black != white:
					valid = False
					break
				if not validate(singles):
					valid = False
					break
				black = 0
				white = 0
				singles = []
			if blocks[col] < 3:
				cell = blocks[col] + col
				if cell % 2 == 0:
					white += 1
				else:
					black += 1
				if len(singles) == 0:
					singles.append([col, col, blocks[col]])
				else:
					singles[-1][1] = col
	print('YES' if valid else 'NO')


__version__ = '1.0'
__date__ = '2021-03-19'
import sys
from operator import itemgetter

def solve(n, m, obstacles):
	if len(obstacles) % 2 == 1:
		return 'NO'
	obstacles.sort(key=itemgetter(0))
	curr = 0
	while curr < m:
		(c1, r1) = obstacles[curr]
		(c2, r2) = obstacles[curr + 1]
		if c1 == c2:
			curr += 2
			continue
		if curr + 2 < m:
			(c3, r3) = obstacles[curr + 2]
			if c2 == c3:
				return 'NO'
		distance = c2 - c1 + r2 - r1
		if distance % 2 == 0:
			return 'NO'
		curr += 2
	return 'YES'

def main(argv=None):
	t = int(input())
	for _ in range(t):
		input()
		(n, m) = map(int, input().split())
		obstacles = list()
		for i in range(m):
			(r, c) = map(int, input().split())
			obstacles.append((c - 1, r - 1))
		print(solve(n, m, obstacles))
	return 0
STATUS = main()
sys.exit(STATUS)


import sys
input = sys.stdin.buffer.readline

def prog():
	for _ in range(int(input())):
		lol = input()
		(n, m) = map(int, input().split())
		a = []
		filled = [3]
		col = [0]
		fail = False
		for i in range(m):
			(r, c) = map(int, input().split())
			a.append([c, r])
		a.sort()
		i = 0
		while i < m:
			if i != m - 1 and a[i][0] == a[i + 1][0]:
				filled.append(3)
				col.append(a[i][0])
				i += 2
			else:
				filled.append(a[i][1])
				col.append(a[i][0])
				i += 1
		filled.append(3)
		col.append(10 ** 9 + 1)
		for i in range(len(filled) - 1):
			if filled[i] == 3:
				continue
			elif filled[i + 1] == 3:
				fail = True
				break
			elif filled[i + 1] == filled[i]:
				if (col[i + 1] - col[i] - 1) % 2 != 0:
					fail = True
					break
				else:
					filled[i + 1] = 3
			elif (col[i + 1] - col[i] - 1) % 2 != 1:
				fail = True
				break
			else:
				filled[i + 1] = 3
		if fail:
			print('NO')
		else:
			print('YES')
prog()


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

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

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] > self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return (flag, prime)

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

def lcm(a, b):
	return a * b // gcd(a, b)

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

@bootstrap
def gdfs(r, p):
	if len(g[r]) == 1 and p != -1:
		yield None
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res
t = N()
for i in range(t):
	e = input()
	(n, m) = RL()
	b = defaultdict(list)
	for i in range(m):
		(r, c) = RL()
		b[c].append(r - 1)
	last = -1
	ans = True
	for k in sorted(b.keys()):
		if last == -1:
			if len(b[k]) != 2:
				last = k
				lb = b[k][0]
		else:
			if k - last & 1:
				lb ^= 1
			if lb in b[k]:
				ans = False
				break
			last = -1
	if last != -1:
		ans = False
	ans = 'YES' if ans else 'NO'
	print(ans)


import sys
z = sys.stdin.readline
w = lambda : map(int, z().split())
for _ in [8] * int(z()):
	z()
	(_, m) = w()
	d = l = 0
	for (x, y) in sorted(([*w()][::-1] for _ in [8] * m)):
		d += (x + y) % 2 * 2 - 1
		if abs(d) > 1 or (l == x and d):
			d = m
		l = x
	print('no' if d else 'yes')


t = int(input())
for tt in range(t):
	input()
	(n, m) = map(int, input().split())
	a = []
	for i in range(m):
		(r, c) = map(int, input().split())
		a.append([c, r])
	a.sort()
	c = 0
	(bc, br) = (-1, -1)
	start = a[0][0]
	end = a[-1][0]
	flg = False
	while start <= end:
		if c < m - 2:
			if a[c + 1][0] == a[c + 2][0]:
				flg = True
				break
		if c < m - 1:
			if a[c][0] == a[c + 1][0]:
				if c < m - 2:
					start = a[c + 2][0]
					c += 2
				else:
					end = -1
			elif a[c + 1][1] == a[c][1]:
				if (a[c + 1][0] - a[c][0]) % 2 != 0:
					if c < m - 2:
						start = a[c + 2][0]
						c += 2
					else:
						end = -1
				else:
					flg = True
					end = -1
			elif (a[c + 1][0] - a[c][0]) % 2 == 0:
				if c < m - 2:
					start = a[c + 2][0]
					c += 2
				else:
					end = -1
			else:
				flg = True
				end = -1
		elif c == m - 1:
			flg = True
			end = -1
		else:
			break
	if flg:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	null = input()
	(n, m) = map(int, input().split())
	x = []
	for _ in range(m):
		(r, c) = map(int, input().split())
		x.append([c - 1, r - 1])
	x.sort()
	s = [[0] * 2 for _ in range(3 * m + 3)]
	l0 = -2
	l = -2
	for (i, j) in x:
		if i - l <= 1:
			i0 = l0 + i - l
		elif l % 2 == i % 2:
			i0 = l0 + 2
		else:
			i0 = l0 + 3
		l0 = i0
		l = i
		s[i0][j] = 1
	ok = 1
	for i in range(l0 + 1):
		(x, y) = s[i]
		if x ^ y:
			if y:
				if not s[i + 1][0]:
					s[i + 1][0] = 1
				else:
					ok = 0
			if x:
				if not s[i + 1][1]:
					s[i + 1][1] = 1
				else:
					ok = 0
		if not ok:
			break
	if m % 2:
		ok = 0
	ans = 'YES' if ok else 'NO'
	print(ans)


t = int(input())
for _ in range(t):
	blocked = []
	non = input()
	(n, m) = map(int, input().split())
	dct = {}
	for times in range(m):
		(r, c) = map(int, input().split())
		if c not in dct:
			dct[c] = r
		else:
			dct[c] = 0
	blocked = zip(dct.keys(), dct.values())
	blocked = sorted(blocked, key=lambda x: (x[0], x[1]))
	can = 0
	con = 3
	prev = 0
	den = 0
	for i in blocked:
		if i[1] == 0:
			if can != 0:
				den = 1
				break
			else:
				continue
		elif can == 0:
			can = 3 - i[1]
			prev = i[0]
		elif (i[0] - prev) % 2 == 1:
			if can == 3 - i[1]:
				can = 0
			else:
				den = 1
				break
		elif can == i[1]:
			can = 0
		else:
			den = 1
			break
	if den == 0:
		if can == 0:
			print('Yes')
		else:
			print('No')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	input()
	a = list()
	(n, m) = map(int, input().split())
	for __ in range(m):
		(x, y) = map(int, input().split())
		a.append((y, x))
	a.sort()
	a.append((10 ** 15, 10 ** 15))
	i = 0
	f = True
	while i != m:
		if i == m - 1:
			f = False
			break
		if a[i][0] == a[i + 1][0]:
			i += 2
		else:
			if (a[i + 1][0] - a[i][0]) % 2 == 0:
				if a[i + 1][1] == a[i][1] or a[i + 2][0] == a[i + 1][0]:
					f = False
					break
			elif a[i + 1][1] != a[i][1] or a[i + 2][0] == a[i + 1][0]:
				f = False
				break
			i += 2
	if f:
		print('YES')
	else:
		print('NO')


def solve(n, a):
	(r1, r2) = (0, 0)
	for i in range(len(a)):
		if a[i][1] == 1 and r1 or (a[i][1] == 2 and r2) or (a[i][1] == 3 and (r2 or r1)):
			print('NO')
			return 0
		x = a[i][1] % 2 + r1
		y = a[i][1] // 2 + r2
		r1 = 1 - x & (x ^ y)
		r2 = 1 - y & (x ^ y)
		if r1 == r2:
			(r1, r2) = (0, 0)
		if i < len(a) - 1 and a[i][0] == a[i + 1][0] - 1 or a[i][0] == n - 1:
			continue
		if i < len(a) - 1 and (a[i + 1][0] - a[i][0]) % 2 == 0 or (i == len(a) - 1 and (n - a[i][0]) % 2 == 0):
			(r1, r2) = (r2, r1)
	if r1 or r2:
		print('NO')
		return 0
	print('YES')
for _ in range(int(input())):
	input()
	(n, m) = [int(x) for x in input().split()]
	a = []
	for _ in range(m):
		(x, y) = [int(x) for x in input().split()]
		a.append([y, x])
	a = sorted(a)
	b = []
	i = 0
	while i < m - 1:
		if a[i][0] == a[i + 1][0]:
			b.append([a[i][0], 3])
			i += 1
		else:
			b.append(a[i])
		i += 1
	if m > 1 and a[-1][0] != a[-2][0]:
		b.append(a[-1])
	if m == 1:
		b = a
	solve(n, b)


def gint():
	return list(map(int, input().split()))
for _ in range(int(input())):
	input()
	(n, m) = gint()
	inp = []
	for i in range(m):
		inp.append(gint())
	inp.sort(key=lambda e: e[0] + 2 * e[1])

	def check(pos):
		if pos % 2 == 0:
			return sum(inp[pos]) % 2 != sum(inp[pos + 1]) % 2
		else:
			return inp[pos][1] != inp[pos + 1][1]
	if m % 2 != 0 or False in list(map(check, range(m - 1))):
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	input()
	(n, m) = map(int, input().split())
	blocked = {}
	for _ in range(m):
		(r, c) = map(int, input().split())
		blocked[c] = blocked.get(c, [False, False])
		blocked[c][r - 1] = True
	bl = [(k, blocked[k]) for k in sorted(list(blocked.keys()))]
	st = -1
	pr = 0
	poss = True
	for (b, o) in bl:
		bc = o.count(True)
		if st == -1 and bc == 2:
			pass
		elif st == -1:
			st = o.index(True)
			pr = b
		else:
			if o[(b - pr + st) % 2]:
				poss = False
				break
			st = -1
	if st != -1:
		poss = False
	print('YES' if poss else 'NO')


import math
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict, deque

def f(n, m, mp):
	cap = 2 * n - m
	if cap % 2 == 1:
		return 'NO'
	blocked = 0
	for i in sorted(mp.keys()):
		if blocked:
			if len(mp[i]) == 2:
				return 'NO'
			currow = mp[i][0]
			if last_blocked[0] == currow:
				if last_blocked[1] % 2 == i % 2:
					return 'NO'
				else:
					blocked = 0
			elif last_blocked[1] % 2 != i % 2:
				return 'NO'
			else:
				blocked = 0
		elif len(mp[i]) == 1:
			blocked = 1
			last_blocked = (mp[i][0], i)
	return 'YES'
t = int(input())
result = []
for i in range(t):
	input()
	mp = defaultdict(list)
	(n, m) = list(map(int, input().split()))
	for i in range(m):
		(r, c) = list(map(int, input().split()))
		mp[c].append(r)
	result.append(f(n, m, mp))
for i in range(t):
	print(result[i])


import sys
from sys import stdin
from collections import deque
tt = int(stdin.readline())
for loop in range(tt):
	stdin.readline()
	(n, m) = map(int, stdin.readline().split())
	C = {}
	Clis = []
	for i in range(m):
		(r, c) = map(int, stdin.readline().split())
		if c not in C:
			C[c] = 0
			Clis.append(c)
		C[c] ^= r
	Clis.append(n + 1)
	C[n + 1] = 3
	Clis.sort()
	now = 0
	ans = 'YES'
	for ind in Clis:
		if C[ind] == 3 and now != 0:
			ans = 'NO'
			break
		if C[ind] == 1:
			if ind % 2 == 0:
				if now == 0:
					now = 2
				elif now == 1:
					now = 0
				else:
					ans = 'NO'
					break
			elif now == 0:
				now = 1
			elif now == 1:
				ans = 'NO'
				break
			else:
				now = 0
		elif C[ind] == 2:
			if ind % 2 == 0:
				if now == 0:
					now = 1
				elif now == 1:
					ans = 'NO'
					break
				else:
					now = 0
			elif now == 0:
				now = 2
			elif now == 1:
				now = 0
			else:
				ans = 'NO'
				break
	print(ans)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(99999)
t = int(input())
for _ in range(t):
	input()
	(n, m) = map(int, input().split())
	blocks = []
	for i in range(m):
		(x, y) = map(int, input().split())
		blocks.append([x, y])
	if m % 2 == 1:
		print('NO')
	else:
		ok = True
		blocks.sort(key=lambda x: x[1])
		for i in range(1, m, 2):
			if i >= 2 and blocks[i - 1][1] == blocks[i - 2][1]:
				ok = False
			if (blocks[i][1] - blocks[i - 1][1] + (1 if blocks[i][0] != blocks[i - 1][0] else 0)) % 2 == 0:
				ok = False
		if ok:
			print('YES')
		else:
			print('NO')


t = int(input())
for ti in range(t):
	tr = input()
	(n, m) = map(int, input().split())
	l = []
	for i in range(m):
		(a, b) = map(int, input().split())
		l.append((a, b))
	l.sort(key=lambda x: x[1])
	p = (-1, -1)
	sta = 0
	ans = True
	for i in l:
		if sta == 0:
			if p[1] == i[1]:
				ans = False
				break
			p = i
			sta = 1
		else:
			if i[0] != p[0]:
				if p[1] - i[1] & 1:
					ans = False
					break
				else:
					sta = 0
			elif p[1] - i[1] & 1:
				sta = 0
			elif p[1] == i[1]:
				sta = 0
			else:
				ans = False
				break
			p = i
	if sta:
		ans = False
	if ans:
		print('YES')
	else:
		print('NO')


from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def si():
	return str(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def lsi():
	return list(map(str, inp().split()))

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)
MOD = 10 ** 9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def inverseFactorials():
	n = len(INV_FACT)
	INV_FACT[n - 1] = inverse(FACT[n - 1])
	for i in range(n - 2, -1, -1):
		INV_FACT[i] = multiply(INV_FACT[i + 1], i + 1)

def coeffBinom(n, k):
	if n < k:
		return 0
	return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n - k]))

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path
for test in range(ii()):
	inp()
	(n, m) = li()
	black = []
	for i in range(m):
		(r, c) = li(-1)
		black.append(2 * c + r)
	black.sort()
	if m % 2 == 1:
		print('NO')
	else:
		ok = 1
		for i in range(m // 2):
			primo = black[2 * i]
			secondo = black[2 * i + 1]
			if 2 * i + 2 < m:
				terzo = black[2 * i + 2]
				if secondo // 2 == terzo // 2:
					ok = 0
			c1 = primo // 2
			c2 = secondo // 2
			r1 = primo % 2
			r2 = secondo % 2
			if r1 != r2:
				if abs(c1 - c2) % 2 == 1:
					ok = 0
			elif abs(c1 - c2) % 2 == 0:
				ok = 0
		if ok:
			print('YES')
		else:
			print('NO')


import sys, os, getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def solve_(mrr, n):
	mrr.append([1, n + 1])
	mrr.append([2, n + 1])
	n = n + 1
	mrr = sorted([(a - 1, b - 1) for (b, a) in mrr])
	prev = 0
	offset = 0
	new_mrr = []
	for (a, b) in mrr:
		if prev + 3 <= a:
			offset += 2 * ((a - (prev + 2)) // 2)
		prev = a
		a = a - offset
		new_mrr.append((a, b))
	mrr = new_mrr
	n = n - offset
	blocked = set(mrr)
	cur_profile = set([(1, 1)])
	for i in range(n):
		new_cur_profile = set()
		for (x, y) in cur_profile:
			curblock = [[x, y], [0, 0]]
			if (i, 0) in blocked:
				curblock[1][0] = 1
			if (i, 1) in blocked:
				curblock[1][1] = 1
			if curblock[0][0] == curblock[1][0] == 0:
				curblock[0][0] = curblock[1][0] = 1
			if curblock[0][1] == curblock[1][1] == 0:
				curblock[0][1] = curblock[1][1] = 1
			if curblock[0][0] == curblock[0][1] == 1:
				new_cur_profile.add(tuple(curblock[1]))
		if (0, 0) in new_cur_profile:
			new_cur_profile.add((1, 1))
		cur_profile = new_cur_profile
		if not cur_profile:
			return 'NO'
	if (1, 1) in cur_profile:
		return 'YES'
	return 'NO'
all_res = []
for case_num in range(int(input())):
	_ = input()
	(n, k) = list(map(int, input().split()))
	mrr = read_matrix(k)
	res = solve(mrr, n)
	print(res)


import sys
input = sys.stdin.buffer.readline

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))
t = int(input())
allAns = []
for _ in range(t):
	input()
	(n, m) = [int(x) for x in input().split()]
	rc = []
	for __ in range(m):
		rc.append([int(x) for x in input().split()])
	rc.sort(key=lambda x: x[1])
	rc.append([1, n + 1])
	rc.append([2, n + 1])
	p1 = 0
	p2 = 0
	ok = True
	for (r, c) in rc:
		if r == 1:
			if (c - 1 - p1) % 2 == 0:
				p1 = c
			elif p2 < c - 1 and (c - 1 - p2) % 2 == 1:
				p1 = c
				p2 = c - 1
			else:
				ok = False
				break
		elif (c - 1 - p2) % 2 == 0:
			p2 = c
		elif p1 < c - 1 and (c - 1 - p1) % 2 == 1:
			p2 = c
			p1 = c - 1
		else:
			ok = False
			break
	if ok:
		allAns.append('YES')
	else:
		allAns.append('NO')
multiLineArrayPrint(allAns)


for _ in range(int(input())):
	input()
	(n, m) = map(int, input().split())
	a = []
	for _ in range(m):
		(r, c) = map(int, input().split())
		a.append((r, c))
	a.sort(key=lambda x: -x[1])
	if m % 2 == 1:
		print('NO')
		continue
	flag = True
	while a:
		(r1, c1) = a.pop()
		(r2, c2) = a.pop()
		if a and a[-1][1] == c2:
			flag = False
			break
		if r1 == r2:
			if (c2 - c1) % 2 == 0:
				flag = False
				break
		elif (c2 - c1) % 2 == 1:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


import sys, os, io
input = sys.stdin.readline
T = int(input())
ans = ['YES'] * T
for t in range(T):
	input()
	(N, M) = map(int, input().split())
	lis = [1, 1]
	A = [list(map(int, input().split())) for _ in range(M)] + [(1, N + 1), (2, N + 1)]
	A.sort(key=lambda x: x[1])
	for (r, c) in A:
		if lis[r - 1] > c:
			ans[t] = 'NO'
		if lis[0] == lis[1]:
			lis = [c, c]
			lis[r - 1] += 1
		elif (c - lis[r - 1]) % 2:
			ans[t] = 'NO'
		else:
			lis = [c + 1, c + 1]
print(*ans, sep='\n')


from io import BytesIO, IOBase
import sys
import math
import os
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def solve():
	input()
	(n, m) = map(int, input().split())
	blocks = []
	for i in range(m):
		(a, b) = map(int, input().split())
		blocks.append([a, b])
	if m % 2:
		print('NO')
		return
	blocks.sort(key=lambda x: [x[1], x[0]])
	lag = 0
	prev_col = -2
	for i in range(m):
		(row, col) = blocks[i]
		if lag == 0:
			if prev_col == col:
				print('NO')
				return
			if row == 2:
				lag = 1
			else:
				lag = 2
		elif lag == 1:
			if row == 1:
				if (col - prev_col) % 2 == 0:
					lag = 0
				else:
					print('NO')
					return
			elif (col - prev_col) % 2 == 1:
				lag = 0
			else:
				print('NO')
				return
		elif row == 2:
			if (col - prev_col) % 2 == 0:
				lag = 0
			else:
				print('NO')
				return
		elif (col - prev_col) % 2 == 1:
			lag = 0
		else:
			print('NO')
			return
		prev_col = col
	if lag == 0:
		print('YES')
	else:
		print('NO')

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


from sys import stdin, stdout

def new_year_puzzle(n, m, rc_a):
	rc_a.sort(key=lambda x: x[1])
	cnt = 0
	i = 0
	while i < m:
		if i + 1 < m and rc_a[i][1] == rc_a[i + 1][1]:
			if cnt != 0:
				return 'NO'
			else:
				i += 1
		elif cnt == 1:
			cnt = 0
		elif cnt == 0:
			if i + 1 < m and (rc_a[i + 1][1] - rc_a[i][1]) % 2 == 0 and (rc_a[i][0] == rc_a[i + 1][0]):
				return 'NO'
			if i + 1 < m and (rc_a[i + 1][1] - rc_a[i][1]) % 2 == 1 and (rc_a[i][0] != rc_a[i + 1][0]):
				return 'NO'
			cnt = 1
		i += 1
	if cnt == 0:
		return 'YES'
	else:
		return 'NO'
t = int(stdin.readline())
for _ in range(t):
	stdin.readline()
	(n, m) = map(int, stdin.readline().split())
	rc_a = []
	for _ in range(m):
		(r, c) = map(int, stdin.readline().split())
		rc_a.append([r, c])
	r = new_year_puzzle(n, m, rc_a)
	stdout.write(str(r) + '\n')


def solve():
	(n, m) = map(int, input().split())
	blocked = {tuple(map(int, input().split())) for _ in range(m)}
	blocked.add((1, n + 1))
	blocked.add((2, n + 1))
	positions = sorted(map(lambda x: x[1], blocked))
	prev = 0
	state = 0
	for pos in positions:
		if pos == prev:
			continue
		tb = (1, pos) in blocked
		bb = (2, pos) in blocked
		dif = pos - prev
		if tb and bb:
			if state != 0:
				return False
		elif tb:
			if state == 0:
				state = 2
			else:
				state = (state + dif) % 2 + 1
				if state == 1:
					return False
				state = 0
		elif state == 0:
			state = 1
		else:
			state = (state + dif) % 2 + 1
			if state == 2:
				return False
			state = 0
		prev = pos
	return True
for _ in range(int(input())):
	input()
	print('Yes' if solve() else 'No')


import sys
import math
from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	a = input()
	(n, m) = map(int, input().split())
	s = set()
	l = set()
	for j in range(m):
		(r, c) = map(int, input().split())
		s.add((r, c))
		l.add(c)
	l = sorted(l)
	p = -1
	for j in l:
		p += 1
		if (1, j) in s and (2, j) in s:
			continue
		if p == len(l) - 1:
			print('NO')
			break
		if (1, j) in s:
			if l[p + 1] - j & 1:
				chk = 2
			else:
				chk = 1
		elif l[p + 1] - j & 1:
			chk = 1
		else:
			chk = 2
		if (chk, l[p + 1]) in s:
			print('NO')
			break
		else:
			s.add((chk, l[p + 1]))
	else:
		print('YES')


def solve():
	(n, m) = map(int, input().split())
	arr = []
	exist = {}
	s = set()
	for i in range(m):
		(a, b) = map(int, input().split())
		exist[a, b] = True
		s.add(b)
	s = sorted(s)
	arr.append(list((0, 3)))
	for i in s:
		if (1, i) in exist and (2, i) in exist:
			arr.append(list((i, 3)))
		elif (1, i) in exist:
			arr.append(list((i, 1)))
		else:
			arr.append(list((i, 2)))
	arr.append(list((n + 1, 3)))
	for i in range(1, len(arr)):
		diff = arr[i][0] - arr[i - 1][0]
		a = arr[i - 1][1]
		b = arr[i][1]
		if a == 3:
			continue
		if b == 3:
			print('NO')
			return
		if a == b:
			if diff % 2 == 0:
				print('NO')
				return
			else:
				arr[i][1] = 3
		elif diff % 2 == 0:
			arr[i][1] = 3
		else:
			print('NO')
			return
	print('YES')

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