A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — $n$ and $k$, where $n$ is even. Next, he takes all the integers from $1$ to $n$, and splits them all into pairs $(a, b)$ (each integer must be in exactly one pair) so that for each pair the integer $(a + k) \cdot b$ is divisible by $4$ (note that the order of the numbers in the pair matters), or reports that, unfortunately for viewers, such a split is impossible.

Burenka really likes such performances, so she asked her friend Tonya to be a magician, and also gave him the numbers $n$ and $k$.

Tonya is a wolf, and as you know, wolves do not perform in the circus, even in a mathematical one. Therefore, he asks you to help him. Let him know if a suitable splitting into pairs is possible, and if possible, then tell it.


-----Input-----

The first line contains one integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The following is a description of the input data sets.

The single line of each test case contains two integers $n$ and $k$ ($2 \leq n \leq 2 \cdot 10^5$, $0 \leq k \leq 10^9$, $n$ is even) — the number of integers and the number being added $k$.

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


-----Output-----

For each test case, first output the string "YES" if there is a split into pairs, and "NO" if there is none.

If there is a split, then in the following $\frac{n}{2}$ lines output pairs of the split, in each line print $2$ numbers — first the integer $a$, then the integer $b$.


-----Examples-----

Input
4
4 1
2 0
12 10
14 11
Output
YES
1 2
3 4
NO
YES
3 4
7 8
11 12
2 1
6 5
10 9
YES
1 2
3 4
5 6
7 8
9 10
11 12
13 14


-----Note-----

In the first test case, splitting into pairs $(1, 2)$ and $(3, 4)$ is suitable, same as splitting into $(1, 4)$ and $(3, 2)$.

In the second test case, $(1 + 0) \cdot 2 = 1 \cdot (2 + 0) = 2$ is not divisible by $4$, so there is no partition.

Difficulty: EASY
Tags: Mathematics

Constructive algorithms

Starter code:

Solutions:
t = int(input())
ans = []
for e in range(t):
	(n, k) = map(int, input().split())
	if k % 4 == 0:
		ans.append('NO')
	elif k % 4 in [1, 3]:
		ans.append('YES')
		for e in range(1, n + 1, 2):
			ans.append(f'{e} {e + 1}')
	else:
		ans.append('YES')
		for e in range(1, n + 1, 2):
			if (e + 1) % 4 == 0:
				ans.append(f'{e} {e + 1}')
			else:
				ans.append(f'{e + 1} {e}')
print('\n'.join(ans))


def generate(n, k):
	res = []
	if not k % 4:
		return ('NO', res)
	if k % 4 % 2:
		for i in range(1, n, 2):
			res.append(f'{i} {i + 1}')
	else:
		for i in range(1, n, 2):
			if not (i + 1) % 4:
				res.append(f'{i} {i + 1}')
		for i in range(1, n, 2):
			if (i + 1) % 4:
				res.append(f'{i + 1} {i}')
	return ('YES', res)
r = []
for i in range(int(input())):
	(n, k) = map(int, input().split())
	r.append(generate(n, k))
for (ans, list) in r:
	print(ans)
	if list != []:
		print(*list, sep='\n')


t = int(input())
possibility = []
for i in range(t):
	(n, k) = [int(j) for j in input().split()]
	if n % 2:
		possibility.append('NO')
	elif not n % 2 and k % 2:
		possibility.append('YES')
		for j in range(1, n + 1, 2):
			possibility.append(f'{j} {j + 1}')
	elif not n % 2 and k % 4:
		possibility.append('YES')
		for j in range(4, n + 1, 4):
			possibility.append(f'{j - 1} {j}')
		for j in range(2, n + 1, 4):
			possibility.append(f'{j} {j - 1}')
	else:
		possibility.append('NO')
for i in possibility:
	print(i)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	if k % 4 == 1 or k % 4 == 3:
		print('YES')
		for i in range(1, n, 2):
			print(f'{i} {i + 1}')
	elif k % 4 == 2:
		print('YES')
		for i in range(1, n, 4):
			print(f'{i + 1} {i}')
		for i in range(3, n, 4):
			print(f'{i} {i + 1}')
	else:
		print('NO')
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	if k % 2 == 1:
		print('YES')
		for i in range(n // 2):
			print(f'{i * 2 + 1} {i * 2 + 2}')
	elif k % 4 == 0:
		print('NO')
	else:
		print('YES')
		for i in range(n // 2):
			if i % 2 == 0:
				print(f'{i * 2 + 2} {i * 2 + 1}')
			else:
				print(f'{i * 2 + 1} {i * 2 + 2}')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k % 2 == 1:
		print('YES')
		for i in range(1, n, 2):
			print(f'{i} {i + 1}')
	elif k % 4 == 2:
		print('YES')
		for i in range(1, n, 4):
			print(f'{i + 1} {i}')
		for i in range(3, n, 4):
			print(f'{i} {i + 1}')
	else:
		print('NO')


num = int(input())
for i in range(num):
	arr = input()
	arr = arr.split(' ')
	n = int(arr[0])
	k = int(arr[1])
	if k % 2 != 0:
		print('YES')
		for j in range(1, n, 2):
			print(f'{j} {j + 1}')
	else:
		arr2 = []
		for j in range(1, n, 2):
			if (j + k) * (j + 1) % 4 == 0:
				arr2.append(f'{j} {j + 1}')
			elif (j + 1 + k) * j % 4 == 0:
				arr2.append(f'{j + 1} {j}')
			else:
				break
		if len(arr2) != n / 2:
			print('NO')
		else:
			print('YES')
			print('\n'.join(arr2))


tc = int(input())
while tc > 0:
	(n, k) = [int(i) for i in input().split()]
	if k % 2 == 1:
		print('YES')
		for i in range(1, n + 1, 2):
			print('{} {}'.format(i, i + 1))
	elif (2 + k) % 4 == 0:
		print('YES')
		for i in range(1, n + 1, 2):
			if (i + 1) % 4 == 0:
				print('{} {}'.format(i, i + 1))
			else:
				print('{} {}'.format(i + 1, i))
	else:
		print('NO')
	tc -= 1


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
mod = 10 ** 9 + 7
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k % 2 == 1:
		print('YES')
		for i in range(0, n, 2):
			print(i + 1, i + 2)
	elif k % 4 == 2:
		print('YES')
		for i in range(4, n + 1, 4):
			print(i - 1, i)
		for i in range(2, n + 1, 4):
			print(i, i - 1)
	else:
		print('NO')
		continue


def codeforces(n, k):
	if k % 4 == 0:
		print('NO')
	else:
		print('YES')
		if k % 2 == 1:
			ind = 1
			while ind < n:
				print(f'{ind} {ind + 1}')
				ind += 2
		elif k % 4 == 2:
			ind = 1
			while ind < n:
				if (ind + 1) % 4 == 0:
					print(f'{ind} {ind + 1}')
				else:
					print(f'{ind + 1} {ind}')
				ind += 2
t = int(input())
for test in range(t):
	(n, k) = [int(i) for i in input().split()]
	codeforces(n, k)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	if k % 4 == 0:
		print('NO')
	else:
		print('YES')
		if k % 2 != 0:
			for i in range(1, n + 1, 2):
				print(f'{i} {i + 1}')
		else:
			flag = False
			for i in range(1, n + 1, 2):
				(a, b) = (i, i + 1) if flag else (i + 1, i)
				print(f'{a} {b}')
				flag = not flag


from sys import stdin, stdout

def ans():
	(n, k) = map(int, stdin.readline().strip().split())
	if k % 4 == 0:
		print('NO')
	elif k % 2 != 0:
		print('YES')
		for x in range(1, n + 1, 2):
			print(x, x + 1)
	else:
		print('YES')
		for x in range(2, n + 1, 2):
			if x % 4 == 0:
				print(x - 1, x)
			else:
				print(x, x - 1)
t = int(stdin.readline())
for _ in range(t):
	ans()


t = int(input())
ans = []
for _ in range(t):
	(n, k) = tuple(map(int, input().split()))
	if k % 4 == 0:
		ans.append('NO')
	elif k % 2 == 1:
		ans.append('YES')
		for i in range(1, n, 2):
			ans.append(str(i) + ' ' + str(i + 1))
	else:
		ans.append('YES')
		for i in range(1, n, 2):
			if (i + 1 + k) % 4 == 0:
				ans.append(str(i + 1) + ' ' + str(i))
			else:
				ans.append(str(i) + ' ' + str(i + 1))
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k % 4 == 0:
		print('NO')
		continue
	if k % 4 == 1:
		print('YES')
		for i in range(1, n, 2):
			print(f'{i} {i + 1}')
		continue
	if k % 4 == 2:
		print('YES')
		for i in range(1, n, 2):
			if i % 4 == 1:
				print(f'{i + 1} {i}')
			else:
				print(f'{i} {i + 1}')
	if k % 4 == 3:
		print('YES')
		for i in range(1, n, 2):
			print(f'{i} {i + 1}')
		continue


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k % 2 == 1:
		print('YES')
		for i in range(1, n + 1, 2):
			print(i, i + 1)
	elif k % 4 == 2:
		print('YES')
		for i in range(1, n // 4 + 1):
			print(4 * i - 1, 4 * i)
		for i in range(1, (n + 2) // 4 + 1):
			print(4 * i - 2, 4 * i - 3)
	elif k % 4 == 0:
		print('NO')


import sys
import collections
import bisect
import math
from functools import lru_cache
for _ in range(int(input())):
	(n, k) = list(map(int, sys.stdin.readline().split()))
	if k % 4 == 0:
		print('NO')
	elif k % 2 == 0:
		print('YES')
		for i in range(1, n + 1, 2):
			if (i + 1) % 4 == 0:
				print(i, i + 1)
			else:
				print(i + 1, i)
	else:
		print('YES')
		for i in range(1, n + 1, 2):
			print(i, i + 1)


import sys
input = sys.stdin.readline

def int_num():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def solve():
	(n, k) = int_list()
	if k % 4 == 0:
		print('NO')
		return
	print('YES')
	for i in range(1, n, 2):
		if i % 4 == 1:
			if k % 4 == 2:
				print(i + 1, i)
			else:
				print(i, i + 1)
		else:
			print(i, i + 1)

def main():
	t = int_num()
	while t:
		solve()
		t -= 1
	return
main()


cases = int(input())
for i in range(cases):
	s = input()
	(n, k) = s.split()
	n = int(n)
	k = int(k) % 4
	if k == 0:
		print('NO')
	else:
		print('YES')
		if k == 1 or k == 3:
			i = 1
			while i < n:
				print('%d %d' % (i, i + 1))
				i += 2
		elif k == 2:
			i = 1
			while i < n:
				if i // 2 % 2:
					print('%d %d' % (i, i + 1))
				else:
					print('%d %d' % (i + 1, i))
				i += 2


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	q = 0
	if b % 4 == 0:
		print('NO')
	else:
		print('YES')
		if b % 2 == 0:
			q = 1
		for i in range(3, a + 1, 4):
			if q == 1:
				print(i - 1, i - 2)
			else:
				print(i - 2, i - 1)
			print(i, i + 1)
		if a % 4 == 2:
			if q == 1:
				print(a, a - 1)
			else:
				print(a - 1, a)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k % 4 == 1 or k % 4 == 3:
		print('YES')
		for i in range(1, n + 1, 2):
			print(str(i) + ' ' + str(i + 1))
	elif k % 4 == 2:
		print('YES')
		for i in range(3, n + 1, 4):
			print(str(i) + ' ' + str(i + 1))
		for i in range(1, n + 1, 4):
			print(str(i + 1) + ' ' + str(i))
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k % 4 == 0:
		print('NO')
	else:
		print('YES')
		if k % 4 == 1 or k % 4 == 3:
			for i in range(1, n + 1, 2):
				print(i, i + 1)
		else:
			for i in range(1, n + 1, 2):
				if (i + 1) % 4 == 2:
					print(i + 1, i)
				else:
					print(i, i + 1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().strip().split())
	l = []
	if k == 0:
		print('NO')
	elif k % 2 == 1:
		print('YES')
		for i in range(1, n + 1, 2):
			print(i, i + 1)
	elif k % 4 == 0:
		print('NO')
	else:
		print('YES')
		for i in range(2, n + 1, 2):
			if i % 4 == 0:
				print(i - 1, i)
			else:
				print(i, i - 1)


t = int(input())
for test_cases in range(t):
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	if k % 4 == 0:
		print('NO')
		continue
	if k % 4 == 1:
		print('YES')
		for index in range(1, n, 2):
			print(str(index) + ' ' + str(index + 1))
		continue
	if k % 4 == 2:
		print('YES')
		for index in range(1, n, 2):
			if index % 4 == 1:
				print(str(index + 1) + ' ' + str(index))
			else:
				print(str(index) + ' ' + str(index + 1))
	if k % 4 == 3:
		print('YES')
		for index in range(1, n, 2):
			print(str(index) + ' ' + str(index + 1))
		continue


qt = int(input())
for i in range(qt):
	(n, k) = map(int, input().split(' '))
	if k % 2 == 1:
		print('YES')
		for i in range(n // 2):
			print(f'{2 * i + 1} {2 * i + 2}')
	elif k % 4 == 2:
		print('YES')
		for i in range(n // 2):
			if (2 * i + 2) % 4 == 0:
				print(f'{2 * i + 1} {2 * i + 2}')
		for i in range(n // 2):
			if (2 * i + 2) % 4 != 0:
				print(f'{2 * i + 2} {2 * i + 1}')
	else:
		print('NO')


for j in range(int(input())):
	(n, k) = map(int, input().split(' '))
	if k == 0:
		print('NO')
	elif k % 2 == 1:
		print('YES')
		for i in range(1, n + 1, 2):
			print(str(i) + ' ' + str(i + 1))
	elif (k + 2) % 4 == 0:
		print('YES')
		for i in range(1, n + 1, 4):
			print(str(i + 1) + ' ' + str(i))
		for i in range(3, n + 1, 4):
			print(str(i) + ' ' + str(i + 1))
	else:
		print('NO')


def solve():
	x = int(input())
	for _ in range(x):
		[n, k] = list(map(int, input().split()))
		used = [False] * n
		pairs = []
		for i in range(0, n, 2):
			v = i + 1
			if not (v + k) * (v + 1) % 4:
				pairs.append([v, v + 1])
			elif not (v + 1 + k) * v % 4:
				pairs.append([v + 1, v])
			else:
				print('NO')
				break
		if len(pairs) == n // 2:
			print('YES')
			for pair in pairs:
				printPair(pair)

def printPair(pair):
	print(f'{pair[0]} {pair[1]}')
solve()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	if k & 1:
		print('YES')
		for i in range(1, n + 1, 2):
			print(i, i + 1)
	else:
		flag = 1
		for i in range(2, n + 1, 2):
			if i % 4 != 0:
				if (i + k) % 4 != 0:
					print('NO')
					flag = 0
					break
		if not flag:
			continue
		print('YES')
		for i in range(1, n + 1, 2):
			if (i + 1) % 4 == 0:
				print(i, i + 1)
			else:
				print(i + 1, i)


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	if k % 4 == 0:
		print('NO')
	elif k % 4 == 2:
		print('YES')
		for i in range(1, n + 1, 2):
			if i % 4 == 1:
				print(i + 1, i)
			else:
				print(i, i + 1)
	else:
		print('YES')
		for i in range(1, n + 1, 2):
			print(i, i + 1)


t = int(input())
for i in range(t):
	(n, m) = input().split()
	m = int(m)
	n = int(n)
	if m % 2 == 1:
		print('YES')
		i = 1
		while i < n:
			print(str(i) + ' ' + str(i + 1))
			i += 2
	elif m % 4 == 2:
		print('YES')
		i = 1
		while 4 * i <= n:
			print(str(4 * i - 1) + ' ' + str(4 * i))
			i += 1
		j = 1
		while 2 * j <= n:
			print(str(2 * j) + ' ' + str(2 * j - 1))
			j += 2
	else:
		print('NO')


iter = int(input())
for z in range(iter):
	(n, k) = list(map(int, input().split(' ')))
	if k & 1:
		print('YES')
		for i in range(1, n + 1, 2):
			print(str(i) + ' ' + str(i + 1))
	elif k % 4 == 0:
		print('NO')
	else:
		print('YES')
		for i in range(3, n + 1, 4):
			print(str(i) + ' ' + str(i + 1))
		for i in range(1, n + 1, 4):
			print(str(i + 1) + ' ' + str(i))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	k %= 4
	if k == 0:
		print('NO')
		continue
	print('YES')
	if k == 2:
		c = 0
		for i in range(1, n + 1, 2):
			if c % 2 == 0:
				print(i + 1, i)
			else:
				print(i, i + 1)
			c += 1
	else:
		for i in range(1, n + 1, 2):
			print(i, i + 1)


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def solve():
	(n, k) = inlt()
	if k % 4 == 0:
		return []
	arr = []
	for a in range(1, n + 1, 2):
		if k & 1 or (a + 1) % 4 == 0:
			arr.append([a, a + 1])
		else:
			arr.append([a + 1, a])
	return arr
for _ in range(inp()):
	ans = solve()
	if not ans:
		print('NO')
	else:
		print('YES')
	for a in ans:
		print(*a)


import sys
s = sys.stdin.read()
lines = s.split('\n')
for line in lines[1:-1]:
	(n, k) = map(int, line.split())
	result_list = []
	if k % 2 == 1:
		for i in range(1, n, 2):
			result_list.append([i, i + 1])
		print('YES')
		for result in result_list:
			print(*result)
	elif k % 4 == 0:
		print('NO')
	else:
		for i in range(1, n, 2):
			if (i + 1) % 4 == 0:
				result_list.append([i, i + 1])
			else:
				result_list.append([i + 1, i])
		print('YES')
		for result in result_list:
			print(*result)


def solve(n, m):
	if m % 2 == 1:
		print('YES')
		for num in range(1, n, 2):
			print(num, num + 1)
	elif m % 4 == 2:
		print('YES')
		for num in range(1, n, 2):
			if (num + 1) % 4 == 0:
				print(num, num + 1)
			else:
				print(num + 1, num)
	else:
		print('NO')
test_cases = int(input())
for tc in range(test_cases):
	arr = [int(i) for i in input().split()]
	solve(arr[0], arr[1])


t = int(input())
for i in range(t):
	p = input()
	p = p.split(' ')
	n = int(p[0])
	k = int(p[1])
	if k % 4 == 1:
		print('YES')
		for j in range(1, n + 1, 2):
			print('{first} {sec}'.format(first=j, sec=j + 1))
	elif k % 4 == 2:
		print('YES')
		if n % 4 == 0:
			for j in range(1, n + 1, 4):
				print('{first} {sec}'.format(first=j + 1, sec=j))
				print('{fir} {sec}'.format(fir=j + 2, sec=j + 3))
		else:
			for j in range(1, n - 1, 4):
				print('{first} {sec}'.format(first=j + 1, sec=j))
				print('{fir} {sec}'.format(fir=j + 2, sec=j + 3))
			print('{fir} {sec}'.format(fir=n, sec=n - 1))
	elif k % 4 == 3:
		print('YES')
		for j in range(1, n + 1, 2):
			print('{fir} {sec}'.format(fir=j, sec=j + 1))
	elif k % 4 == 0:
		print('NO')


for _ in range(0, int(input())):
	(n, k) = map(int, input().split())
	if k % 2 == 0:
		z = 0
		if (2 + k) * 1 % 4 == 0:
			print('YES')
			f = True
			for i in range(1, n, 2):
				if f:
					print(i + 1, i)
					f = False
				else:
					print(i, i + 1)
					f = True
		else:
			print('NO')
	else:
		z = 0
		if (1 + k) * 2 % 4 == 0:
			print('YES')
			f = True
			for i in range(1, n, 2):
				print(i, i + 1)
		else:
			print('NO')


xx = int(input())
for jj in range(xx):
	(n, k) = [int(i) for i in input().split(' ')]
	if k % 4 == 0:
		print('NO')
	else:
		print('YES')
		if k % 2 == 1:
			for i in range(1, n + 1, 2):
				print(i, i + 1)
		else:
			for i in range(2, n + 1, 2):
				if i % 4 == 0:
					print(i - 1, i)
				else:
					print(i, i - 1)


t = int(input())

def mainfunc(n, k):
	if k % 2 == 1:
		print('YES')
		for i in range(1, n, 2):
			print(i, i + 1)
	elif k % 4 == 0:
		print('NO')
	else:
		print('YES')
		for i in range(4, n + 1, 4):
			print(i - 1, i)
		for i in range(2, n + 1, 4):
			print(i, i - 1)
for j in range(t):
	a = input().split()
	n = int(a[0])
	k = int(a[1])
	mainfunc(n, k)


def solution(n, k):
	k = k % 4
	if k == 0:
		print('NO')
		return
	print('YES')
	if k == 2:
		print_reverse = True
		for i in range(2, n + 1, 2):
			if print_reverse:
				print(i, i - 1)
				print_reverse = False
			else:
				print(i - 1, i)
				print_reverse = True
	else:
		for i in range(2, n + 1, 2):
			print(i - 1, i)
t = int(input())
while t:
	(n, k) = [int(x) for x in input().strip().split(' ')]
	solution(n, k)
	t -= 1


tests = int(input())
while tests > 0:
	tests -= 1
	(n, k) = list(map(int, input().split(' ')))
	pairs = []
	for x in range(0, n, +2):
		if (x + 1 + k) * (x + 2) % 4 == 0:
			pairs.append([x + 1, x + 2])
		elif (x + 2 + k) * (x + 1) % 4 == 0:
			pairs.append([x + 2, x + 1])
		else:
			print('NO')
			pairs = []
			break
	if len(pairs) > 0:
		print('YES')
		for x in pairs:
			print('{} {}'.format(x[0], x[1]))


n = int(input())
for _ in range(n):
	arr = [int(x) for x in input().split()]
	n = arr[0]
	k = arr[1]
	if k % 2 == 1:
		print('YES')
		for i in range(1, n + 1, 2):
			print('%d %d' % (i, i + 1))
	else:
		even = []
		odd = []
		for i in range(1, n + 1):
			if i % 2 == 1:
				odd.append(i)
			elif i % 4 == 0:
				even.append(i)
			elif (i + k) % 4 == 0:
				even.append(i)
		if len(even) == len(odd):
			print('YES')
			for i in range(1, n + 1, 2):
				if (i + 1) % 4 == 0:
					print('%d %d' % (i, i + 1))
				else:
					print('%d %d' % (i + 1, i))
		else:
			print('NO')


for _ in range(int(input())):
	l = list(map(int, input().split()))
	if l[-1] % 4 == 0:
		print('NO')
	else:
		print('YES')
		if l[-1] % 4 == 2:
			for i in range(1, l[0] + 1, 2):
				if (i + 1) % 4 == 0:
					print(i, i + 1)
				else:
					print(i + 1, i)
		else:
			for i in range(1, l[0] + 1, 2):
				print(i, i + 1)


cas = int(input())
for t in range(cas):
	(n, k) = list(map(int, input().split()))
	results = []
	d = {}
	for a in range(1, n, 2):
		b = a + 1
		if (a + k) * b % 4 == 0:
			results.append([a, b])
		elif (b + k) * a % 4 == 0:
			results.append([b, a])
	if len(results) != n / 2:
		print('NO')
	else:
		print('YES')
		for pair in results:
			print(f'{pair[0]} {pair[1]}')


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k % 4 == 0:
		print('NO')
	elif k % 4 == 1:
		print('YES')
		for i in range(1, n, 2):
			print(i, i + 1)
	elif k % 4 == 2:
		print('YES')
		for i in range(1, n, 2):
			if i % 4 == 1:
				print(i + 1, i)
			else:
				print(i, i + 1)
	elif k % 4 == 3:
		print('YES')
		for i in range(1, n, 2):
			print(i, i + 1)


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	if k % 2 != 0:
		print('YES')
		for j in range(2, n + 1, 2):
			print(j - 1, j)
	elif k % 4 == 0:
		print('NO')
	else:
		print('YES')
		for b in range(4, n + 1, 4):
			print(b - 1, b)
		for a in range(2, n + 1, 4):
			print(a, a - 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k % 2 == 1:
		print('YES')
		for i in range(1, n, 2):
			print(i, i + 1)
	elif (k + 2) % 4 != 0:
		print('NO')
		continue
	else:
		print('YES')
		ct = 4
		while ct <= n:
			print(ct - 1, ct)
			ct += 4
		for i in range(2, n + 1, 4):
			if i % 4 != 0:
				print(i, i - 1)


t = int(input())
for u in range(t):
	(n, p) = map(int, input().split())
	if p % 4 == 0:
		print('NO')
	else:
		print('YES')
		if p % 2 == 0:
			for i in range(1, n, 2):
				if (i + 1) % 4 == 0:
					print(i, i + 1)
				else:
					print(i + 1, i)
		else:
			for i in range(1, n, 2):
				print(i, i + 1)


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	if y % 4 == 0:
		print('NO')
	else:
		print('YES')
		for i in range(1, x + 1, 2):
			(a, b) = (i, i + 1)
			if (a + y) * b % 4 == 0:
				print(str(a) + ' ' + str(b))
			else:
				print(str(b) + ' ' + str(a))


def get(n, k):
	if k % 4 == 0 or k == 0:
		print('NO')
	elif k % 2 == 0:
		print('YES')
		return m(n)
	else:
		print('YES')
		return p(n)

def m(n):
	i = 1
	while i < n:
		if (i + 1) % 4 == 0:
			print(i, i + 1)
		else:
			print(i + 1, i)
		i = i + 2

def p(n):
	i = 1
	while i < n:
		print(i, i + 1)
		i = i + 2
t = 0
t = int(input())
for x in range(t):
	(x, y) = input().split()
	n = int(x)
	k = int(y)
	get(n, k)