You are given two integers b and w. You have a chessboard of size 10^9 × 10^9 with the top left cell at (1; 1), the cell (1; 1) is painted white.

Your task is to find a connected component on this chessboard that contains exactly b black cells and exactly w white cells. Two cells are called connected if they share a side (i.e. for the cell (x, y) there are at most four connected cells: (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)). A set of cells is called a connected component if for every pair of cells C_1 and C_2 from this set, there exists a sequence of cells c_1, c_2, ..., c_k such that c_1 = C_1, c_k = C_2, all c_i from 1 to k are belong to this set of cells and for every i ∈ [1, k - 1], cells c_i and c_{i + 1} are connected.

Obviously, it can be impossible to find such component. In this case print "NO". Otherwise, print "YES" and any suitable connected component.

You have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 10^5) — the number of queries. Then q queries follow.

The only line of the query contains two integers b and w (1 ≤ b, w ≤ 10^5) — the number of black cells required and the number of white cells required.

It is guaranteed that the sum of numbers of cells does not exceed 2 ⋅ 10^5 (∑ w + ∑ b ≤ 2 ⋅ 10^5).

Output

For each query, print the answer to it.

If it is impossible to find the required component, print "NO" on the first line.

Otherwise, print "YES" on the first line. In the next b + w lines print coordinates of cells of your component in any order. There should be exactly b black cells and w white cells in your answer. The printed component should be connected.

If there are several answers, you can print any. All coordinates in the answer should be in the range [1; 10^9].

Example

Input


3
1 1
1 4
2 5


Output


YES
2 2
1 2
YES
2 3
1 3
3 3
2 2
2 4
YES
2 3
2 4
2 5
1 3
1 5
3 3
3 5

Difficulty: MEDIUM_HARD
Tags: Implementation

Constructive algorithms

Starter code:

Solutions:
from sys import stdin, stdout
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys

class merge_find:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n
		self.lista = [[_] for _ in range(n)]

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]
		self.lista[a] += self.lista[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def all_factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def fibonacci_modP(n, MOD):
	if n < 2:
		return 1
	return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n, p):
	if p <= n:
		return 0
	res = p - 1
	for i in range(n + 1, p):
		res = res * cached_fn(InverseEuler, i, p) % p
	return res

def binary(n, digits=20):
	b = bin(n)[2:]
	b = '0' * (digits - len(b)) + b
	return b

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def generate_primes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	return prime
factorial_modP = []

def warm_up_fac(MOD):
	global factorial_modP, fac_warmup
	if fac_warmup:
		return
	factorial_modP = [1 for _ in range(fac_warmup_size + 1)]
	for i in range(2, fac_warmup_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warmup = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	global fac_warmup, factorial_modP
	if not fac_warmup:
		warm_up_fac(MOD)
		fac_warmup = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def display_2D_list(li):
	for i in li:
		print(i)

def prefix_sum(li):
	sm = 0
	res = []
	for i in li:
		sm += i
		res.append(sm)
	return res

def get_int():
	return int(stdin.readline().strip())

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

def get_list():
	return list(map(int, stdin.readline().split()))
import heapq, itertools
pq = []
entry_finder = {}
REMOVED = '<removed-task>'

def add_task(task, priority=0):
	if task in entry_finder:
		remove_task(task)
	count = next(counter)
	entry = [priority, count, task]
	entry_finder[task] = entry
	heapq.heappush(pq, entry)

def remove_task(task):
	entry = entry_finder.pop(task)
	entry[-1] = REMOVED

def pop_task():
	while pq:
		(priority, count, task) = heapq.heappop(pq)
		if task is not REMOVED:
			del entry_finder[task]
			return task
	raise KeyError('pop from an empty priority queue')
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def ncr(n, r):
	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

def binary_serach(i, li):
	fn = lambda x: li[x] - x // i
	x = -1
	b = len(li)
	while b >= 1:
		while b + x < len(li) and fn(b + x) > 0:
			x += b
		b = b // 2
	return x
TestCases = True
testingMode = False
fac_warmup_size = 10 ** 5 + 100
optimiseForReccursion = False
from math import factorial

def main():
	(b, w) = get_tuple()
	(maxi, mini) = (max(b, w), min(b, w))
	points = []
	if maxi <= mini * 3 + 1:
		print('YES')
		if w > b:
			z = 0
		else:
			z = 1
		for i in range(2 * mini):
			points.append([2 + i + z, 2])
		rem = maxi - mini
		if rem != 0:
			points.append([3 + z + i, 2])
		rem -= 1
		for j in range(3 + z, 3 + i + z + 1, 2):
			if rem > 0:
				points.append([j, 1])
				rem -= 1
			if rem > 0:
				points.append([j, 3])
				rem -= 1
		for i in points:
			display_list(i)
	else:
		print('NO')
if TestCases:
	for i in range(get_int()):
		cProfile.run('main()') if testingMode else main()
else:
	(cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()


import atexit, io, sys
input_lines = sys.stdin.read().splitlines()
input = iter(input_lines).__next__
out_buffer = io.StringIO()
sys.stdout = out_buffer

@atexit.register
def write():
	sys.__stdout__.write(out_buffer.getvalue())

def line():
	inp = input().split()
	if len(inp) == 1:
		return int(inp[0])
	return map(int, inp)
from itertools import repeat, cycle
q = line()
for _ in repeat(None, q):
	(b, w) = line()
	p = sorted([b, w])
	if p[1] > p[0] * 3 + 1:
		print('NO')
		continue
	print('YES')
	e = b < w
	r = p[1] - p[0]
	for i in range(e + 2, e + 2 + p[0] * 2):
		print(i, 2)
		if i % 2 == e:
			for j in (-1, 1):
				if r:
					print(i, 2 + j)
					r -= 1
	if r:
		print(e + 1, 2)


q = int(input())
for i in range(q):
	(b, w) = map(int, input().split())
	mn = min(b, w)
	mx = max(b, w)
	if mx > 3 * mn + 1:
		print('NO')
	elif b <= w:
		bk = []
		wh = []
		c = 0
		for i in range(b):
			bk.append((3, 2 + c))
			c += 2
		c = 0
		for i in range(b):
			wh.append((3, 3 + c))
			c += 2
		wh.append((3, 1))
		for i in range(0, len(bk)):
			r = bk[i]
			wh.append((r[0] + 1, r[1]))
			wh.append((r[0] - 1, r[1]))
		wh = wh[:w]
		ans = bk + wh
		print('YES')
		for i in ans:
			print(*i)
	else:
		bk = []
		wh = []
		c = 0
		for i in range(w):
			wh.append((3, 3 + c))
			c += 2
		c = 0
		for i in range(w):
			bk.append((3, 4 + c))
			c += 2
		bk.append((3, 2))
		for i in range(0, len(wh)):
			r = wh[i]
			bk.append((r[0] + 1, r[1]))
			bk.append((r[0] - 1, r[1]))
		bk = bk[:b]
		ans = bk + wh
		print('YES')
		for i in ans:
			print(*i)


import sys
input = sys.stdin.readline
q = int(input())
for i in range(q):
	(b, w) = map(int, input().split())
	(a, c) = sorted([b, w])
	if a * 3 + 1 < c:
		print('NO')
		continue
	print('YES')
	if b >= w:
		t = 2
		b -= w
		while w > 0:
			print(2, t)
			print(2, t + 1)
			t += 2
			w -= 1
		t = 2
		while b > 1:
			print(1, t)
			print(3, t)
			t += 2
			b -= 2
		if b:
			print(2, 1)
	else:
		t = 3
		w -= b
		while b > 0:
			print(2, t)
			print(2, t + 1)
			t += 2
			b -= 1
		t = 3
		while w > 1:
			print(1, t)
			print(3, t)
			t += 2
			w -= 2
		if w:
			print(2, 2)


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')
for j in range(int(input())):
	(b, w) = map(int, input().split())
	if b > 3 * w + 1 or w > 3 * b + 1:
		print('NO')
	else:
		start = [10 ** 7 + 1, 10 ** 7]
		if w < b:
			(w, b) = (b, w)
			start = [10 ** 7, 10 ** 7]
		diff = w - b
		ans = []
		v0 = min(w, b)
		for s in range(v0):
			ans.append((start[0] + 2 * s, start[1]))
			ans.append((start[0] + 2 * s + 1, start[1]))
		for s in range(v0):
			cord = ans[2 * s]
			if diff >= 2:
				ans.append((cord[0], cord[1] + 1))
				ans.append((cord[0], cord[1] - 1))
				diff -= 2
			elif diff == 1:
				ans.append((cord[0], cord[1] + 1))
				diff -= 1
			else:
				break
		if diff == 1:
			ans.append((start[0] - 1, start[1]))
			diff -= 1
		print('YES')
		for s in range(len(ans)):
			print(*ans[s])


from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
	(b, w) = [int(i) for i in input().split()]
	if (w - 1) / 3 <= b <= 3 * w + 1:
		print('YES')
		if w < b:
			v = 0
		else:
			v = 1
			(b, w) = (w, b)
		for i in range(2 * w):
			print(str(i + 1) + ' ' + str(2 + v))
		b -= w
		if b % 2 == 1:
			print(str(2 * w + 1) + ' ' + str(2 + v))
		for i in range(b // 2):
			print(str(2 * i + 2) + ' ' + str(1 + v))
			print(str(2 * i + 2) + ' ' + str(3 + v))
	else:
		print('NO')


from collections import deque
for _ in range(int(input())):
	ar = list(map(int, input().split()))
	ans = []
	d = {}
	(a, b) = ar
	s = deque()

	def bst(i, j, num):
		if i <= 0 or j <= 0 or i >= 10 ** 9 or (j >= 10 ** 9) or (str(i) + '!' + str(j) in d) or (ar[num] == 0):
			return
		d[str(i) + '!' + str(j)] = 1
		ar[num] -= 1
		ans.append([i, j])
		num = not num
		if ar[num]:
			s.append([i + 1, j, num])
		if ar[num]:
			s.append([i - 1, j, num])
		if ar[num]:
			s.append([i, j - 1, num])
		if ar[num]:
			s.append([i, j + 1, num])
	if ar[1]:
		s.append([100000, 100000, 1])
	else:
		s.append([4, 5, 0])
	while len(s) and sum(ar):
		(f, g, h) = list(s.pop())
		bst(f, g, h)
	if len(ans) == a + b:
		print('YES')
		for ijarun in ans:
			print(ijarun[0], ijarun[1])
	else:
		print('NO')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
for _ in range(int(input())):
	(b, w) = map(int, input().split())
	if max(b, w) > 3 * min(b, w) + 1:
		print('NO')
		continue
	print('YES')
	if b > w:
		for i in range(2 * w):
			print(i + 3, 3)
		b -= w
		for i in range(min(b, w)):
			print(2 * (i + 1) + 1, 4)
		b -= w
		for i in range(min(b, w)):
			print(2 * (i + 1) + 1, 2)
		b -= w
		if b > 0:
			print(2, 3)
	else:
		(b, w) = (w, b)
		for i in range(2 * w):
			print(i + 3, 2)
		b -= w
		for i in range(min(b, w)):
			print(2 * (i + 1) + 1, 3)
		b -= w
		for i in range(min(b, w)):
			print(2 * (i + 1) + 1, 1)
		b -= w
		if b > 0:
			print(2, 2)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n < m:
		(n, m) = (m, n)
		ans = 1
	else:
		ans = 2
	if n > 3 * m + 1:
		print('NO')
	else:
		print('YES')
		for i in range(1, m * 2 + 1):
			print(i + ans, 3)
		if n > m:
			print(ans, 3)
			for i in range(1, min(n - m - 1, m) * 2, 2):
				print(ans + i, 2)
			if n - m - 1 > m:
				for i in range(1, (n - m * 2 - 1) * 2, 2):
					print(ans + i, 4)


from sys import stdin, stdout
import collections
Q = int(input())
ans = [0] * Q
for i in range(Q):
	(B, W) = [int(x) for x in stdin.readline().split()]
	mini = (B - 1) // 3 + 1 * ((B - 1) % 3 != 0)
	maxi = 3 * B + 1
	if W < mini or W > maxi:
		print('NO')
	else:
		print('YES')
		b = B
		w = W
		if b < w:
			for i in range(b):
				print(2, 2 * i + 3)
			tmp = w
			for i in range(b + 1):
				if tmp > 0:
					print(2, 2 * i + 2)
					tmp -= 1
				else:
					break
			for i in range(b):
				if tmp > 0:
					print(1, 2 * i + 3)
					tmp -= 1
				else:
					break
				if tmp > 0:
					print(3, 2 * i + 3)
					tmp -= 1
				else:
					break
		elif b == w:
			for i in range(b):
				print(2, 2 * i + 1)
				print(2, 2 * i + 2)
		elif b > w:
			for i in range(w):
				print(2, 2 * i + 2)
			tmp = b
			for i in range(w + 1):
				if tmp > 0:
					print(2, 2 * i + 1)
					tmp -= 1
				else:
					break
			for i in range(w):
				if tmp > 0:
					print(1, 2 * i + 2)
					tmp -= 1
				else:
					break
				if tmp > 0:
					print(3, 2 * i + 2)
					tmp -= 1
				else:
					break


q = int(input())
for _ in range(q):
	(b, w) = map(int, input().split())
	if w == b:
		print('YES')
		for i in range(w + b):
			print(1, i + 1)
	elif w > b:
		if w > 3 * b + 1:
			print('NO')
		else:
			print('YES')
			for i in range(2 * b + 1):
				print(2, i + 2)
			w -= b + 1
			if 0 < w <= b:
				for i in range(w):
					print(1, 2 * i + 3)
			elif w > b:
				for i in range(b):
					print(1, 2 * i + 3)
				w -= b
				for i in range(w):
					print(3, 2 * i + 3)
	elif b > 3 * w + 1:
		print('NO')
	else:
		print('YES')
		for i in range(2 * w + 1):
			print(2, i + 1)
		b -= w + 1
		if 0 < b <= w:
			for i in range(b):
				print(1, 2 * i + 2)
		elif b > w:
			for i in range(w):
				print(1, 2 * i + 2)
			b -= w
			for i in range(b):
				print(3, 2 * i + 2)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
for i in range(t):
	(b, w) = map(int, input().split())
	if w == b:
		print('YES')
		for i in range(1, 2 * b + 1):
			print(2, i)
	elif 3 * b + 1 >= w > b:
		print('YES')
		for i in range(3, 2 * b + 2):
			print(2, i)
		target = w - b + 1
		for i in range(1, b + 1):
			if target != 0:
				print(1, 2 * i + 1)
				target -= 1
			else:
				break
		for i in range(1, b + 1):
			if target != 0:
				print(3, 2 * i + 1)
				target -= 1
			else:
				break
		if target != 0:
			print(2, 2)
			target -= 1
		if target != 0:
			print(2, 2 * b + 2)
			target -= 1
	elif 3 * w + 1 >= b > w:
		print('YES')
		for i in range(2, 2 * w + 1):
			print(2, i)
		target = b - w + 1
		for i in range(1, w + 1):
			if target != 0:
				print(1, 2 * i)
				target -= 1
			else:
				break
		for i in range(1, w + 1):
			if target != 0:
				print(3, 2 * i)
				target -= 1
			else:
				break
		if target != 0:
			print(2, 1)
			target -= 1
		if target != 0:
			print(2, 2 * w + 1)
			target -= 1
	else:
		print('NO')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

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

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

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
for _ in range(inp()):
	(b, w) = inpl()
	(mi, ma) = (min(b, w), max(b, w))
	MA = mi + (mi - 1) * 2 + 3
	if ma > MA:
		print('NO')
		continue
	res = []
	y = 2
	while ma >= 3 and mi >= 1 and (ma > mi):
		res.append((2, y))
		res.append((1, y + 1))
		res.append((2, y + 1))
		res.append((3, y + 1))
		y += 2
		ma -= 3
		mi -= 1
	for i in range(ma):
		res.append((2, y))
		res.append((2, y + 1))
		y += 2
	if ma > mi:
		res.pop()
	if ma < mi:
		res.append((2, 1))
	tmp = 1 if b > w else 0
	print('YES')
	for (x, y) in res:
		print(x, y + tmp)


from sys import stdin

def color(x, y):
	return int((x + y) % 2 == 0)

def gen_cells(x, y, k):
	for i in range(x, x + k):
		yield (i, y)
	for i in range(x, x + k, 2):
		yield (i, y + 1)
		yield (i, y - 1)
	yield (x - 1, y)
	yield (x + k, y)
for query in range(int(stdin.readline())):
	(b, w) = map(int, stdin.readline().split())
	if max(b, w) > 4 + 3 * (min(b, w) - 1):
		print('NO')
		continue
	print('YES')
	(x, y) = (10 ** 7, 10 ** 7)
	if b < w:
		x += 1
	for (i, point) in zip(range(b + w), gen_cells(x, y, min(b, w) * 2 - 1)):
		print('%d %d' % point)


for _ in range(int(input())):
	(b, w) = map(int, input().split())
	if b <= w:
		if w > 3 * b + 1:
			print('NO')
		else:
			print('YES')
			x = 2
			y = 3
			for i in range(b):
				print(x + 2 * i, y)
			for j in range(min(w, b + 1)):
				print(x - 1 + 2 * j, y)
			if 2 * b + 1 >= w > b + 1:
				for j in range(min(w - b - 1, b)):
					print(x + 2 * j, y - 1)
			if 3 * b + 1 >= w > 2 * b + 1:
				for j in range(b):
					print(x + 2 * j, y - 1)
				for j in range(w - 2 * b - 1):
					print(x + 2 * j, y + 1)
	elif b > 3 * w + 1:
		print('NO')
	else:
		print('YES')
		x = 2
		y = 2
		for i in range(w):
			print(x + 2 * i, y)
		for j in range(min(b, w + 1)):
			print(x - 1 + 2 * j, y)
		if 2 * w + 1 >= b > w + 1:
			for j in range(min(b - w - 1, w)):
				print(x + 2 * j, y - 1)
		if 3 * w + 1 >= b > 2 * w + 1:
			for j in range(w):
				print(x + 2 * j, y - 1)
			for j in range(b - 2 * w - 1):
				print(x + 2 * j, y + 1)


q = int(input())
for i in range(q):
	(b, w) = map(int, input().split())
	coord = []
	if b > w:
		for j in range(3, 2 * w + 4):
			coord.append((j, 2))
		b -= w
		b -= 1
		mx = 2 * w
		if b > mx:
			print('NO')
			continue
		else:
			for j in range(min(b, w)):
				coord.append(((j + 2) * 2, 1))
			b -= w
			if b > 0:
				for j in range(min(b, w)):
					coord.append(((j + 2) * 2, 3))
		print('YES')
		for j in coord:
			print(*j)
	elif b < w:
		for j in range(2, 2 * b + 3):
			coord.append((j, 2))
		w -= b
		w -= 1
		mx = 2 * b
		if w > mx:
			print('NO')
			continue
		else:
			for j in range(min(b, w)):
				coord.append(((j + 2) * 2 - 1, 1))
			w -= b
			if w > 0:
				for j in range(min(b, w)):
					coord.append(((j + 2) * 2 - 1, 3))
		print('YES')
		for j in coord:
			print(*j)
	else:
		for j in range(1, b + w + 1):
			coord.append((j, 1))
		print('YES')
		for j in coord:
			print(*j)


q = int(input())
for i in range(q):
	(b, w) = map(int, input().strip().split())
	if b > 3 * w + 1 or w > 3 * b + 1:
		print('NO')
	else:
		print('YES')
		if b >= w:
			c = w
			while c > 0:
				c = c - 1
				print(' '.join(list(map(str, [3, 3 + 2 * c]))))
			c = w - 1
			lb = b - (w - 1)
			while c > 0:
				c = c - 1
				print(' '.join(list(map(str, [3, 4 + 2 * c]))))
			lb = lb - w
			if lb >= 0:
				c = w
			else:
				c = lb + w
			while c > 0:
				c = c - 1
				print(' '.join(list(map(str, [2, 3 + 2 * c]))))
			if lb > 0:
				lb = lb - w
				if lb >= 0:
					c = w
				else:
					c = lb + w
				while c > 0:
					c = c - 1
					print(' '.join(list(map(str, [4, 3 + 2 * c]))))
				lb = lb - 1
				if lb >= 0:
					print(' '.join(['3', '2']))
				lb = lb - 1
				if lb >= 0:
					print(' '.join(['3', str(3 + 2 * (w - 1) + 1)]))
		if w > b:
			c = b
			while c > 0:
				c = c - 1
				print(' '.join(list(map(str, [2, 3 + 2 * c]))))
			c = b - 1
			lb = w - (b - 1)
			while c > 0:
				c = c - 1
				print(' '.join(list(map(str, [2, 4 + 2 * c]))))
			lb = lb - b
			if lb >= 0:
				c = b
			else:
				c = lb + b
			while c > 0:
				c = c - 1
				print(' '.join(list(map(str, [1, 3 + 2 * c]))))
			if lb > 0:
				lb = lb - b
				if lb >= 0:
					c = b
				else:
					c = lb + b
				while c > 0:
					c = c - 1
					print(' '.join(list(map(str, [3, 3 + 2 * c]))))
				lb = lb - 1
				if lb >= 0:
					print(' '.join(['2', '2']))
				lb = lb - 1
				if lb >= 0:
					print(' '.join(['2', str(3 + 2 * (b - 1) + 1)]))


from sys import stdin, stdout
riga = stdin.readline()
query = int(riga)
for i in range(query):
	riga = stdin.readline()
	test = riga.split()
	b = int(test[0])
	w = int(test[1])
	sol = []
	x = 5
	y = 4
	if max(b, w) > 3 * min(b, w) + 1:
		stdout.write('NO\n')
	else:
		for i in range(x, min(b, w) * 2 + x, 2):
			sol.append([i, y])
			sol.append([i + 1, y])
		if w > b:
			sol.append([4, 4])
		else:
			sol.append([x + 2 * w, 4])
			x = 6
		for i in range(min(w, b), max(w, b), 2):
			sol.append([x, y + 1])
			sol.append([x, y - 1])
			x = x + 2
		stdout.write('YES\n')
		for i in range(b + w):
			stdout.write(str(sol[i][0]) + ' ' + str(sol[i][1]) + '\n')


def solve(b, w, ans):
	if b == w:
		curr = ['YES']
		count = 0
		(x, y) = (1, 1)
		while count != 2 * b:
			curr.append((x, y))
			y += 1
			count += 1
		ans.append(curr)
		return
	curr = []
	whites = []
	blacks = []
	if b > w:
		(x, y) = (2, 1)
		while w > 0 and b > 0:
			if y % 2 != 0:
				blacks.append((x, y))
				b -= 1
			else:
				whites.append((x, y))
				w -= 1
			y += 1
		for i in whites:
			blacks.append((i[0] - 1, i[1]))
			b -= 1
			if b == 0:
				break
			blacks.append((i[0] + 1, i[1]))
			b -= 1
			if b == 0:
				break
		if b != 0:
			blacks.append((whites[-1][0], whites[-1][1] + 1))
			b -= 1
		if b != 0:
			ans.append(['NO'])
			return
		curr.append('YES')
		for i in blacks:
			curr.append(i)
		for i in whites:
			curr.append(i)
		ans.append(curr)
		return
	(x, y) = (3, 1)
	while w > 0 and b > 0:
		if y % 2 != 0:
			whites.append((x, y))
			w -= 1
		else:
			blacks.append((x, y))
			b -= 1
		y += 1
	for i in blacks:
		if w == 0:
			break
		whites.append((i[0] - 1, i[1]))
		w -= 1
		if w == 0:
			break
		whites.append((i[0] + 1, i[1]))
		w -= 1
	if w != 0:
		whites.append((blacks[-1][0], blacks[-1][1] + 1))
		w -= 1
	if w != 0:
		ans.append(['NO'])
		return
	curr.append('YES')
	for i in blacks:
		curr.append(i)
	for i in whites:
		curr.append(i)
	ans.append(curr)

def main():
	ans = []
	q = int(input())
	for i in range(q):
		(b, w) = map(int, input().split())
		solve(b, w, ans)
	for i in ans:
		for j in range(len(i)):
			if j == 0:
				print(i[j])
			else:
				print(i[j][0], i[j][1])
main()


def main():
	t = int(input())
	while t > 0:
		t -= 1
		line = input().split()
		n = int(line[0])
		m = int(line[1])
		(xo, yo) = (2, 3)
		if m < n:
			(n, m) = (m, n)
			yo = 2
		cnt = n * 3 + 1
		if m > cnt:
			print('NO')
			continue
		ans = []
		for i in range(n):
			ans.append((xo, yo))
			yo += 2
		for i in range(n):
			m -= 1
			ans.append((ans[i][0], ans[i][1] + 1))
			if m == 0:
				break
		if m > 0:
			m -= 1
			ans.append((ans[0][0], ans[0][1] - 1))
		if m > 0:
			for i in range(n):
				m -= 1
				ans.append((ans[i][0] - 1, ans[i][1]))
				if m == 0:
					break
				m -= 1
				ans.append((ans[i][0] + 1, ans[i][1]))
				if m == 0:
					break
		print('YES')
		for x in ans:
			print(str(x[0]) + ' ' + str(x[1]))
main()


import sys
for _ in range(int(sys.stdin.readline())):
	(b, w) = [int(i) for i in sys.stdin.readline().split()]
	if b > w:
		dif = b - w
		if dif <= 2 * w + 1:
			print('YES')
			for i in range(2, 2 * w + 2):
				print(2, i)
			if dif & 1:
				print(2, 1)
			for i in range(1, dif // 2 + 1):
				print(1, 2 * i)
				print(3, 2 * i)
		else:
			print('NO')
	else:
		dif = w - b
		if dif <= 2 * b + 1:
			print('YES')
			for i in range(2, 2 * b + 2):
				print(2, i)
			if dif & 1:
				print(2, 2 * b + 2)
			for i in range(1, dif // 2 + 1):
				print(1, 2 * i + 1)
				print(3, 2 * i + 1)
		else:
			print('NO')


import sys
t = int(input())
for _ in range(t):
	(b, w) = map(int, sys.stdin.readline().split())
	if b > w:
		x = 2
		y = 2
		m1 = w
		m2 = b
	else:
		x = 2
		y = 3
		m1 = b
		m2 = w
	if m2 > m1 * 3 + 1:
		print('NO')
	else:
		print('YES')
		for i in range(m1):
			print(x + 2 * i, y)
			print(x + 2 * i + 1, y)
		for i in range(min(m1, m2 - m1)):
			print(x + 2 * i, y + 1)
		for i in range(min(m1, m2 - 2 * m1)):
			print(x + 2 * i, y - 1)
		if m2 == m1 * 3 + 1:
			print(x - 1, y)


for _ in range(int(input())):
	(b, w) = map(int, input().split())
	if max(b, w) > 3 * min(b, w) + 1:
		print('NO')
		continue
	print('YES')
	(x, y) = (3, 3)
	if b > w:
		b -= w - 1
	else:
		(b, w) = (w, b)
		x -= 1
		b -= w - 1
	if b > 0:
		print(x - 1, y)
		b -= 1
	for i in range(w):
		print(x, y)
		if b > 0:
			print(x, y - 1)
			b -= 1
		if b:
			print(x, y + 1)
			b -= 1
		if i != w - 1:
			print(x + 1, y)
		x += 2
	if b > 0:
		print(x - 1, y)


t = int(input())
for i in range(t):
	(b, w) = map(int, input().split())
	if max(b, w) > min(b, w) * 3 + 1:
		print('NO')
	else:
		print('YES')
		if b > w:
			x = 2
			y = 2
			mini = w
			maxi = b
		else:
			x = 3
			y = 2
			mini = b
			maxi = w
		for i in range(mini):
			print(x + 2 * i, y)
			print(x + 2 * i + 1, y)
		z = min(mini, maxi - mini)
		for i in range(z):
			print(x + 2 * i, y - 1)
		z1 = min(maxi - (z + mini), mini)
		for i in range(min(maxi - (z + mini), mini)):
			print(x + 2 * i, y + 1)
		if maxi == 3 * mini + 1:
			print(x - 1, y)


import sys
import os
from io import IOBase, BytesIO

def main():
	for tc in range(int(input())):
		(b, w) = get_ints()
		(x, y) = (3, 2)
		if b > w:
			f = 1
			(b, w) = (w, b)
			x += 1
		if w > 3 * b + 1:
			print('NO')
			continue
		ans = [(x - 1, y), (x, y + 1), (x, y - 1)]
		right = [(x + 1, y)]
		ans1 = [(x, y)]
		p = x + 2
		for i in range(b - 1):
			ans1.append((p, y))
			right.append((p + 1, y))
			ans.append((p, y - 1))
			ans.append((p, y + 1))
			p += 2
		print('YES')
		for i in ans1:
			print(*i)
		for i in right:
			print(*i)
		for i in range(w - len(right)):
			print(*ans[i])
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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 get_array():
	return list(map(int, sys.stdin.readline().split()))

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

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


import sys
input = sys.stdin.readline

def solve(b, w):
	origW = w
	origB = b
	res = []
	pos = [2, 2]
	if b >= w:
		for i in range(1, w + 1):
			res.append([2, 2 * i])
			res.append([2, 2 * i + 1])
			b -= 1
			w -= 1
		if b > 0:
			res.append([2, 1])
			b -= 1
		for startPos in ([1, 2], [3, 2]):
			pos = startPos
			while b > 0 and pos[1] <= 2 * origW:
				if sum(pos) % 2 != 0:
					res.append(pos.copy())
					b -= 1
				pos[1] += 1
	else:
		for i in range(1, b + 1):
			res.append([2, 2 * i + 1])
			res.append([2, 2 * i + 2])
			b -= 1
			w -= 1
		if w > 0:
			res.append([2, 2])
			w -= 1
		for startPos in ([1, 3], [3, 3]):
			pos = startPos
			while w > 0 and pos[1] <= 2 * origB + 1:
				if sum(pos) % 2 == 0:
					res.append(pos.copy())
					w -= 1
				pos[1] += 1
	return res

def main():
	q = int(input())
	for _ in range(q):
		(b, w) = map(int, input().split())
		if w > 3 * b + 1 or b > 3 * w + 1:
			print('NO')
		else:
			print('YES')
			res = solve(b, w)
			for row in res:
				print(*row)
main()


for _ in range(int(input())):
	(b, w) = map(int, input().split())
	if b < w:
		(b, w) = (w, b)
		offset = 1
	else:
		offset = 2
	if b > 3 * w + 1:
		print('NO')
	else:
		print('YES')
		for x in range(1, w * 2 + 1):
			print(offset + x, 3)
		if b > w:
			print(offset, 3)
			for x in range(1, min(b - w - 1, w) * 2, 2):
				print(offset + x, 2)
			if b - w - 1 > w:
				for x in range(1, (b - w * 2 - 1) * 2, 2):
					print(offset + x, 4)


import sys
input = sys.stdin.readline

def output(a, b):
	sys.stdout.write(str(a) + ' ' + str(b) + '\n')
q = int(input())
for testcases in range(q):
	(b, w) = map(int, input().split())
	if w > 4 + (b - 1) * 3 or b > 4 + (w - 1) * 3:
		print('NO')
		continue
	print('YES')
	if b <= w:
		for i in range(b * 2):
			output(4, 3 + i)
		w -= b
		if w:
			output(4, 2)
			w -= 1
		count = 0
		while w:
			if count % 2 == 0:
				output(3, 3 + count // 2 * 2)
			else:
				output(5, 3 + count // 2 * 2)
			count += 1
			w -= 1
	else:
		for i in range(w * 2):
			output(5, 3 + i)
		b -= w
		if b:
			output(5, 2)
			b -= 1
		count = 0
		while b:
			if count % 2 == 0:
				output(4, 3 + count // 2 * 2)
			else:
				output(6, 3 + count // 2 * 2)
			count += 1
			b -= 1


for _ in range(int(input())):
	(b, w) = map(int, input().split())
	y = 2
	if w > b:
		y = 3
		(b, w) = (w, b)
	if b > 3 * w + 1:
		print('NO')
		continue
	print('YES')
	if b > w:
		print('1 ' + str(y))
		b -= 1
	for x in range(2, 2 * w + 2, 2):
		print(str(x) + ' ' + str(y))
	for x in range(3, 2 * min(b, w) + 3, 2):
		print(str(x) + ' ' + str(y))
	y += 1
	for x in range(2, 2 * min(b - w, w) + 2, 2):
		print(str(x) + ' ' + str(y))
	y -= 2
	for x in range(2, 2 * (b - 2 * w) + 2, 2):
		print(str(x) + ' ' + str(y))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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')

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()
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))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

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

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

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

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
from decimal import *
from math import *

def solve():
	if 1:
		(b, w) = sep()
		r = 3
		if b > w:
			r = 2
			(b, w) = (w, b)
		if w > 3 * b + 1:
			print('NO')
		else:
			print('YES')
			res1 = [f'{r} 1']
			res2 = []
			for i in range(b):
				res1.append(f'{r} {2 * i + 2}')
				res1.append(f'{r} {2 * i + 3}')
				res2.append(f'{r - 1} {2 * i + 2}')
				res2.append(f'{r + 1} {2 * i + 2}')
			res = (res1 + res2)[:b + w]
			print('\n'.join(res))
testcase(int(inp()))


def naiveSolve():
	return

def main():
	q = int(input())
	allans = []
	for _ in range(q):
		ans = []
		wb = readIntArr()[::-1]
		avail = [[], []]
		if wb[1] > wb[0]:
			i = 2
			j = 3
		else:
			i = j = 2
		while wb[(i + j) % 2] > 0:
			wb[(i + j) % 2] -= 1
			ans.append([i, j])
			avail[(i + j + 1) % 2].append([i - 1, j])
			avail[(i + j + 1) % 2].append([i + 1, j])
			j += 1
		while avail[0] and wb[0] > 0:
			ans.append(avail[0].pop())
			wb[0] -= 1
		while avail[1] and wb[1] > 0:
			ans.append(avail[1].pop())
			wb[1] -= 1
		if wb[0] == wb[1] == 0:
			allans.append(['YES'])
			allans.extend(ans)
		else:
			allans.append(['NO'])
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(l, r):
	print('? {} {}'.format(l, r))
	sys.stdout.flush()
	return int(input())

def answerInteractive(x):
	print('! {}'.format(x))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
from math import gcd, floor, ceil
for _abc in range(1):
	main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(b, w) = map(int, input().split())
	if min(b, w) * 3 + 1 < max(b, w):
		print('NO')
		continue
	ans = []
	(x, y) = (2, 2)
	if b < w:
		x = 3
	while b and w:
		ans.append((x, y))
		ans.append((x, y - 1))
		y += 2
		b -= 1
		w -= 1
	y -= 2
	rem = max(b, w)
	if rem:
		ans.append((x, y + 1))
		rem -= 1
	while rem:
		ans.append((x - 1, y))
		rem -= 1
		if rem:
			ans.append((x + 1, y))
			rem -= 1
		y -= 2
	print('YES')
	for l in ans:
		print(*l)


def one_case():
	(b, w) = map(int, input().split())
	(sx, sy) = (2, 2)
	if b < w:
		(sx, sy) = (2, 3)
	(mi, ma) = (min(b, w), max(b, w))
	if ma > mi * 3 + 1:
		print('NO')
		return
	print('YES')
	l1 = min(ma, mi + 1)
	l2 = min(ma - l1, mi)
	l3 = ma - l1 - l2
	for i in range(mi):
		print(sx, sy + 2 * i)
	for i in range(l1):
		print(sx, sy - 1 + 2 * i)
	for i in range(l2):
		print(sx - 1, sy + 2 * i)
	for i in range(l3):
		print(sx + 1, sy + 2 * i)
t = int(input())
for i in range(t):
	one_case()


q = int(input())
while q:
	(b, w) = map(int, input().split())
	if b == w:
		print('YES')
		for i in range(b + w):
			print(i + 1, 1)
	elif b < w:
		if w > 3 * b + 1:
			print('NO')
		else:
			print('YES')
			black = b
			index = 3
			while black:
				print(index, 2)
				index += 2
				black -= 1
			white = b + 1
			index = 2
			while white:
				print(index, 2)
				index += 2
				white -= 1
			extra_white = w - (b + 1)
			if extra_white <= b:
				index = 3
				while extra_white:
					print(index, 1)
					index += 2
					extra_white -= 1
			else:
				index = 3
				t = b
				while t:
					print(index, 1)
					index += 2
					t -= 1
				r = extra_white - b
				index = 3
				while r:
					print(index, 3)
					index += 2
					r -= 1
	elif b > 3 * w + 1:
		print('NO')
	else:
		print('YES')
		white = w
		index = 2
		while white:
			print(index, 2)
			index += 2
			white -= 1
		black = w + 1
		index = 1
		while black:
			print(index, 2)
			index += 2
			black -= 1
		extra_black = b - (w + 1)
		if extra_black <= w:
			index = 2
			while extra_black:
				print(index, 1)
				index += 2
				extra_black -= 1
		else:
			index = 2
			t = w
			while t:
				print(index, 1)
				index += 2
				t -= 1
			r = extra_black - w
			index = 2
			while r:
				print(index, 3)
				index += 2
				r -= 1
	q -= 1


from sys import stdin, stdout, exit
from collections import defaultdict
q = int(input())
for it in range(q):
	(b, w) = map(int, stdin.readline().split())
	ans = []
	if b < w:
		for i in range(b):
			ans.append((2 + 2 * i, 3))
		for i in range(b + 1):
			if w > 0:
				ans.append((1 + 2 * i, 3))
				w -= 1
		for i in range(b):
			if w > 0:
				ans.append((2 + 2 * i, 2))
				w -= 1
			if w > 0:
				ans.append((2 + 2 * i, 4))
				w -= 1
		if w > 0:
			stdout.write('NO\n')
			continue
	else:
		for i in range(w):
			ans.append((2 + 2 * i, 2))
		for i in range(w + 1):
			if b > 0:
				ans.append((1 + 2 * i, 2))
				b -= 1
		for i in range(w):
			if b > 0:
				ans.append((2 + 2 * i, 1))
				b -= 1
			if b > 0:
				ans.append((2 + 2 * i, 3))
				b -= 1
		if b > 0:
			stdout.write('NO\n')
			continue
	stdout.write('YES\n')
	for (x, y) in ans:
		stdout.write(str(x) + ' ' + str(y) + '\n')


def col(x, y):
	return (x + y) % 2 == 0
t = int(input())
for z in range(t):
	(w, b) = map(int, input().split())
	if b < w:
		sx = 3
		sy = 2
	else:
		sx = 2
		sy = 2
	x = sx
	y = sy
	if max(b, w) > min(b, w) * 2 + 1 + min(b, w):
		print('NO')
	else:
		print('YES')
		mn = min(w, b)
		mx = max(w, b)
		for i in range(mn):
			c = col(x, y)
			if c:
				b -= 1
			else:
				w -= 1
			print(x, y)
			y += 1
			c = col(x, y)
			if c:
				b -= 1
			else:
				w -= 1
			print(x, y)
			y += 1
		if not w and (not b):
			continue
		c = col(x, y)
		if c:
			b -= 1
		else:
			w -= 1
		print(x, y)
		mx = max(b, w)
		x = sx
		y = sy + 1
		while mx > 0:
			if mx > 1:
				print(x + 1, y)
				print(x - 1, y)
				y += 2
				mx -= 2
			else:
				print(x + 1, y)
				mx -= 1


T = int(input())
for _ in range(T):
	(b, w) = map(int, input().split())
	r = 3
	if b > w:
		r = 2
		(b, w) = (w, b)
	if w > 3 * b + 1:
		print('NO')
	else:
		print('YES')
		res1 = [f'{r} 1']
		res2 = []
		for i in range(b):
			res1.append(f'{r} {2 * i + 2}')
			res1.append(f'{r} {2 * i + 3}')
			res2.append(f'{r - 1} {2 * i + 2}')
			res2.append(f'{r + 1} {2 * i + 2}')
		res = (res1 + res2)[:b + w]
		print('\n'.join(res))


n = int(input())
for _ in range(n):
	(b, w) = map(int, input().split())
	if max(b, w) <= 3 * min(b, w) + 1:
		dx = 0 if min(b, w) == w else 1
		mn = min(b, w)
		mx = max(b, w)
		print('YES')
		for _ in range(mn):
			print(2 + dx + 2 * _, 2)
		for _ in range(mn):
			if mx == 0:
				break
			print(2 + dx + 1 + 2 * _, 2)
			mx -= 1
		for _ in range(mn):
			if mx == 0:
				break
			print(2 + dx + 2 * _, 3)
			mx -= 1
		for _ in range(mn):
			if mx == 0:
				break
			print(2 + dx + 2 * _, 1)
			mx -= 1
		if mx:
			print(1 + dx, 2)
	else:
		print('NO')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(b, w) = map(int, input().split())
	if w > 3 * b + 1 or b > 3 * w + 1:
		print('NO')
	elif w == b:
		print('YES')
		for i in range(w):
			print(1, i + 1)
			print(2, i + 1)
	elif w > b:
		print('YES')
		col = 3
		while w > b and b > 0:
			print(1, col)
			print(2, col)
			print(3, col)
			w -= 2
			b -= 1
			if w > b:
				print(2, col + 1)
				w -= 1
			col += 2
		if w == 1 and b == 0:
			print(2, 2)
		else:
			for i in range(w):
				print(4, i + 3)
				print(5, i + 3)
	elif b > w:
		print('YES')
		col = 2
		while b > w and w > 0:
			print(1, col)
			print(2, col)
			print(3, col)
			b -= 2
			w -= 1
			if b > w:
				print(2, col + 1)
				b -= 1
			col += 2
		if b == 1 and w == 0:
			print(2, 1)
		else:
			for i in range(w):
				print(4, i + 2)
				print(5, i + 2)


q = int(input())
for _ in range(q):
	(b, w) = map(int, input().split())
	if b == w:
		print('YES')
		for i in range(b + w):
			print('1 ' + str(i + 1))
	elif b > w:
		if b > 3 * w + 1:
			print('NO')
		else:
			print('YES')
			b -= w + 1
			for i in range(w * 2 + 1):
				print('2 ' + str(i + 1))
			cnt = 2
			while b > 0:
				print('1 ' + str(cnt))
				b -= 1
				if b == 0:
					break
				print('3 ' + str(cnt))
				b -= 1
				cnt += 2
	elif w > b:
		if w > 3 * b + 1:
			print('NO')
		else:
			print('YES')
			w -= b + 1
			for i in range(b * 2 + 1):
				print('3 ' + str(i + 1))
			cnt = 2
			while w > 0:
				print('2 ' + str(cnt))
				w -= 1
				if w == 0:
					break
				print('4 ' + str(cnt))
				w -= 1
				cnt += 2


import sys
input = sys.stdin.readline
Q = int(input())
for _ in range(Q):
	(A, B) = map(int, input().split())
	if A > 3 * B + 1 or B > 3 * A + 1:
		print('NO')
	elif A == B:
		print('YES')
		for i in range(A):
			print(1, i + 1)
			print(2, i + 1)
	elif A > B:
		print('YES')
		for i in range(B * 2 + 1):
			print(2, i + 1)
		c = A - B - 1
		a = 0
		while c:
			a += 2
			print(1, a)
			c -= 1
			if c == 0:
				break
			print(3, a)
			c -= 1
	elif B > A:
		print('YES')
		for i in range(A * 2 + 1):
			print(3, i + 1)
		c = B - A - 1
		a = 0
		while c:
			a += 2
			print(2, a)
			c -= 1
			if c == 0:
				break
			print(4, a)
			c -= 1


q = int(input())
for i in range(q):
	(b, w) = [int(i) for i in input().split()]
	if b <= w and w > 3 * b + 1 or (w < b and b > 3 * w + 1):
		print('NO')
	else:
		print('YES')
		if b < w:
			mas = []
			a = 3
			print(2, a)
			mas.append([1, 3])
			mas.append([2, 2])
			mas.append([3, 3])
			for j in range(b + b - 2):
				a += 1
				print(2, a)
				if a % 2 == 1:
					mas.append([1, a])
					mas.append([3, a])
			mas.append([2, 2 + 2 * b])
			w = w - b + 1
			ass = 0
			while w != 0:
				print(' '.join((str(k) for k in mas[ass])))
				ass += 1
				w -= 1
		else:
			mas = []
			a = 2
			print(2, a)
			mas.append([1, 2])
			mas.append([2, 1])
			mas.append([3, 2])
			for j in range(w + w - 2):
				a += 1
				print(2, a)
				if a % 2 == 0:
					mas.append([1, a])
					mas.append([3, a])
			mas.append([2, 1 + 2 * w])
			b = b - w + 1
			ass = 0
			while b != 0:
				print(' '.join((str(k) for k in mas[ass])))
				ass += 1
				b -= 1


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(b, w) = map(int, input().split())
	t = 3
	if b > w:
		t = 2
		(b, w) = (w, b)
	if w > 3 * b + 1:
		print('NO')
		continue
	print('YES')
	print(1, t)
	w -= 1
	cur = 2
	while b > 0:
		if w > b:
			print(cur, t - 1)
			w -= 1
		if w > b:
			print(cur, t + 1)
			w -= 1
		print(cur, t)
		b -= 1
		if w != 0:
			print(cur + 1, t)
		cur += 2
		w -= 1


q = int(input().strip())

def get_color(x, y):
	if x % 2 == 0 and y % 2 == 0:
		return 'w'
	elif x % 2 != 0 and y % 2 != 0:
		return 'b'
	elif x % 2 != 0 and y % 2 == 0:
		return 'b'
	else:
		return 'w'

class cell:

	def __init__(self, x, y, color):
		self.x = x
		self.y = y
		self.color = color
for i in range(q):
	(b, w) = map(int, input().strip().split())
	ans = []
	if b > w:
		less = 'w'
		to_break = w
		to_not_break = b
		to_start = (100000, 100000)
	else:
		less = 'b'
		to_break = b
		to_not_break = w
		to_start = (99999, 100000)
	turn = less
	to_next = to_start
	while to_break > 0:
		ans.append(to_next)
		to_next = (to_next[0] + 1, to_next[1])
		if turn == less:
			to_break -= 1
		else:
			to_not_break -= 1
		turn = 'b' if turn == 'w' else 'w'
	for i in range(to_start[0], to_next[0], 2):
		if to_not_break <= 0:
			break
		ans.append((i, to_start[1] + 1))
		to_not_break -= 1
	if to_not_break > 0:
		for i in range(to_start[0], to_next[0], 2):
			if to_not_break <= 0:
				break
			ans.append((i, to_start[1] - 1))
			to_not_break -= 1
		if to_not_break <= 0:
			print('YES')
			for i in ans:
				print('{} {}'.format(i[0], i[1]))
		elif to_not_break == 1:
			print('YES')
			for i in ans:
				print('{} {}'.format(i[0], i[1]))
			print('{} {}'.format(to_start[0] - 1, to_start[1]))
		elif to_not_break == 2:
			print('YES')
			for i in ans:
				print('{} {}'.format(i[0], i[1]))
			print('{} {}'.format(to_start[0] - 1, to_start[1]))
			print('{} {}'.format(to_next[0], to_next[1]))
		else:
			print('NO')
	else:
		print('YES')
		for i in ans:
			print('{} {}'.format(i[0], i[1]))


for _ in range(int(input())):
	(b, w) = tuple(map(int, input().split()))
	if 3 * min(b, w) + 1 >= max(b, w):
		print('YES')
		(nax, nin) = (max(b, w), min(b, w))
		if b <= w:
			(startx, starty) = (2, 3)
		else:
			(startx, starty) = (2, 2)
		for i in range(2 * nin - 1):
			print(2, i + starty)
		rem = nax - (nin - 1)
		turn = False
		i = 0
		while rem > 2:
			if not turn:
				print(1, starty + (i << 1))
			else:
				print(3, starty + (i << 1))
				i += 1
			rem -= 1
			turn = not turn
		if rem > 0:
			print(2, starty - 1)
			rem -= 1
			if rem > 0:
				print(2, (nin << 1) + starty - 1)
	else:
		print('NO')


for i in range(int(input())):
	(a, b) = map(int, input().split())
	dx = 0
	if a > b:
		(a, b) = (b, a)
		dx = 1
	if b > 3 * a + 1:
		print('NO')
		continue
	print('YES')
	s = a + a + 1
	for j in range(1, s):
		print(f'{j} {3 + dx}')
	tmp_b = a
	count = 0
	while tmp_b < b and count < a:
		tmp_b += 1
		count += 1
		print(f'{count + count} {2 + dx}')
	count = 0
	while tmp_b < b and count < a:
		tmp_b += 1
		count += 1
		print(f'{count + count} {4 + dx}')
	if tmp_b < b:
		print(f'{s} {3 + dx}')


import sys

def main():
	N = int(sys.stdin.readline().strip())
	for _ in range(N):
		(b, w) = [int(x) for x in sys.stdin.readline().strip().split()]
		x = 2
		y = 2
		if b < w:
			(b, w) = (w, b)
			x += 1
		if b > w * 3 + 1:
			print('NO')
			continue
		print('YES')
		for i in range(w):
			print(x + i * 2, y)
			print(x + 1 + i * 2, y)
		b -= w
		up = min(b, w)
		for i in range(up):
			print(x + i * 2, y - 1)
		b -= up
		down = min(b, w)
		for i in range(down):
			print(x + i * 2, y + 1)
		b -= down
		if b:
			assert b == 1
			print(x - 1, y)
main()


for i in range(int(input())):
	(b, w) = map(int, input().split())
	if b > 3 * w + 1 or w > 3 * b + 1:
		print('NO')
	else:
		print('YES')
		if b <= w:
			for c in range(1, 2 * b + 1):
				print(c, 3)
			if w - b > 0:
				print(2 * b + 1, 3)
				j = w - 1 - b
				while j > 0:
					if j > b:
						print(2 * (j - b), 2)
					if j <= b:
						print(2 * j, 4)
					j -= 1
		else:
			for c in range(1, 2 * w + 1):
				print(c, 2)
			if b - w > 0:
				print(2 * w + 1, 2)
				j = b - 1 - w
				while j > 0:
					if j > w:
						print(2 * (j - w), 1)
					if j <= w:
						print(2 * j, 3)
					j -= 1


t = int(input())
for z2 in range(t):
	(y, x) = input().split()
	x = int(x)
	y = int(y)
	sum = x + y
	if x != y and min(x, y) * 3 + 1 < max(x, y):
		print('NO')
	elif x is y:
		print('YES')
		for z in range(1, 2 * x + 1):
			print('1 ' + str(z))
	else:
		print('YES')
		if x > y:
			for z in range(2, 2 * y + 3):
				print('2 ' + str(z))
			sum = sum - (2 * y + 1)
			if sum > 0:
				for z in range(3, 2 * y + 3, 2):
					print('3 ' + str(z))
					sum -= 1
					if sum == 0:
						break
			if sum > 0:
				for z in range(3, 2 * y + 3, 2):
					print('1 ' + str(z))
					sum -= 1
					if sum == 0:
						break
		else:
			for z in range(3, 2 * x + 4):
				print('2 ' + str(z))
			sum = sum - (2 * x + 1)
			if sum > 0:
				for z in range(4, 2 * x + 4, 2):
					print('3 ' + str(z))
					sum -= 1
					if sum == 0:
						break
			if sum > 0:
				for z in range(4, 2 * x + 4, 2):
					print('1 ' + str(z))
					sum -= 1
					if sum == 0:
						break