Alice has a lovely piece of cloth. It has the shape of a square with a side of length $a$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $b$ centimeters (where $b < a$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).

Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?


-----Input-----

The first line contains a number $t$ ($1 \leq t \leq 5$) — the number of test cases.

Each of the next $t$ lines describes the $i$-th test case. It contains two integers $a$ and $b~(1 \leq b < a \leq 10^{11})$ — the side length of Alice's square and the side length of the square that Bob wants.


-----Output-----

Print $t$ lines, where the $i$-th line is the answer to the $i$-th test case. Print "YES" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print "NO".

You can print each letter in an arbitrary case (upper or lower).


-----Example-----
Input
4
6 5
16 13
61690850361 24777622630
34 33

Output
YES
NO
NO
YES



-----Note-----

The figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $6^2 - 5^2 = 36 - 25 = 11$, which is prime, so the answer is "YES". [Image] 

In the second case, the area is $16^2 - 13^2 = 87$, which is divisible by $3$. [Image] 

In the third case, the area of the remaining piece is $61690850361^2 - 24777622630^2 = 3191830435068605713421$. This number is not prime because $3191830435068605713421 = 36913227731 \cdot 86468472991 $.

In the last case, the area is $34^2 - 33^2 = 67$.

Difficulty: EASY
Tags: Number theory

Mathematics

Starter code:

Solutions:
import sys
I = sys.stdin.readline

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True
for _ in range(int(I())):
	(a, b) = map(int, I().split())
	if a - b == 1:
		if is_prime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def isprime(n):
	if n == 2:
		return True
	if n % 2 == 0:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a - b == 1:
		if isprime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import sys
small_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]

def probably_prime(n):
	if n < 2:
		return False
	for p in small_primes:
		if n < p * p:
			return True
		if n % p == 0:
			return False
	(r, s) = (0, n - 1)
	while s % 2 == 0:
		r += 1
		s //= 2
	for a in small_primes:
		x = pow(a, s, n)
		if x == 1 or x == n - 1:
			continue
		for _ in range(r - 1):
			x = pow(x, 2, n)
			if x == n - 1:
				break
		else:
			return False
	return True
ans = []
tc = int(sys.stdin.readline())
for case in range(tc):
	(a, b) = [int(x) for x in sys.stdin.readline().split()]
	area = a * a - b * b
	if probably_prime(area):
		print('YES')
	else:
		print('NO')
sys.exit()


import math

def isPrime(j):
	for z in range(2, int(math.sqrt(j) + 2)):
		if j % z == 0:
			return 0
	return 1
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	d = isPrime(a + b)
	if a - b == 1 and d == 1:
		print('YES')
	else:
		print('NO')


import math

def isPrime(n):
	if n < 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if isPrime(a + b) and a - b == 1:
		print('YES')
	else:
		print('NO')


import math

def list_primes_upto(upto: int):
	uptop1 = upto + 1
	uptom1 = upto - 1
	pcl = [1 for x in range(uptop1)]
	lprimes = []
	if upto >= 2:
		lprimes.append(2)
	if upto >= 3:
		lprimes.append(3)
	i = 5
	while i < uptom1:
		ix2 = i * 2
		if pcl[i] == 1:
			lprimes.append(i)
			for k in range(i * i, uptop1, ix2):
				pcl[k] = 0
		ip2 = i + 2
		ip2x2 = ip2 * 2
		if pcl[ip2] == 1:
			lprimes.append(ip2)
			for k in range(ip2 * ip2, uptop1, ip2x2):
				pcl[k] = 0
		i += 6
	if i <= upto:
		ix2 = i * 2
		if pcl[i] == 1:
			lprimes.append(i)
			for k in range(i * i, uptop1, ix2):
				pcl[k] = 0
	return lprimes
t = int(input())
tests = []
for q in range(t):
	tests.append([int(x) for x in input().split()])
check_limit = 0
for (a, b) in tests:
	if a - b == 1:
		check_limit = max(check_limit, a + b)
primes = list_primes_upto(int(math.sqrt(check_limit)) + 1)
for (a, b) in tests:
	yes = True
	if a - b != 1:
		yes = False
	if yes:
		apb = a + b
		is_apb_prime = True
		for p in primes:
			if not is_apb_prime or p >= apb:
				break
			is_apb_prime = is_apb_prime and apb % p != 0
		yes = yes and is_apb_prime
	print('YES' if yes else 'NO')


def isPrime(n):
	if n == 1:
		return False
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
	return True
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a - b == 1 and isPrime(a + b):
		print('YES')
	else:
		print('NO')


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
while t > 0:
	(a, b) = map(int, input().split(' '))
	if a - b == 1:
		res = a + b
		val = isPrime(res)
		if val == True:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	t -= 1


from math import sqrt

def isprime(num):
	for d in range(2, int(sqrt(num)) + 2):
		if num % d == 0:
			return False
	return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b == 1 and isprime(a + b):
		print('YES')
	else:
		print('NO')


from math import sqrt
from itertools import count, islice

def isPrime(n):
	return n > 1 and all((n % i for i in islice(count(2), int(sqrt(n) - 1))))
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ans = False
	if a - b == 1:
		x = a + b
		ans = isPrime(x)
	if ans:
		print('YES')
	else:
		print('NO')


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
	else:
		bo = True
		for i in range(2, int(math.sqrt(a + b)) + 1):
			if (a + b) % i == 0:
				bo = False
		print('YES NO'.split()[not bo])


def prime(n):
	if n < 2:
		return False
	elif n % 2 == 0:
		return False
	else:
		for k in range(3, 1 + int(n ** 0.5), 2):
			if n % k == 0:
				return False
	return True
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	n = a + b
	if a - b > 1:
		print('NO')
	elif prime(n):
		print('YES')
	else:
		print('NO')


from math import sqrt
from itertools import count, islice
n = int(input())

def isPrime(n):
	return n > 1 and all((n % i for i in islice(count(2), int(sqrt(n) - 1))))

def eval_(a, b):
	if abs(a - b) != 1:
		return 'NO'
	result = isPrime(a + b)
	if result:
		return 'YES'
	else:
		return 'NO'
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	print(eval_(a, b))


t = int(input())
while t > 0:
	(a, b) = list(map(int, input().split()))
	if a - b != 1:
		print('NO')
	else:
		num = a + b
		num2 = int(num ** 0.5)
		num3 = 2
		ans = 0
		while num3 <= num2:
			if num % num3 == 0:
				ans = 1
			num3 += 1
		if ans == 1:
			print('NO')
		else:
			print('YES')
	t -= 1


import math

def checkprime(a):
	flag = 0
	c = int(math.sqrt(a))
	for i in range(2, c + 1):
		if a % i == 0:
			flag = 1
	if flag > 0:
		return 'NO'
	else:
		return 'YES'
t = int(input())
for i in range(0, t):
	(t1, t2) = input().split()
	t1 = int(t1)
	t2 = int(t2)
	diff = t1 + t2
	if t1 - t2 > 1:
		print('NO')
	else:
		print(checkprime(diff))


def prime(n):
	i = 2
	j = 0
	while i ** 2 <= n and j != 1:
		if n % i == 0:
			j = 1
		i += 1
	if j == 1:
		return False
	else:
		return True
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a - b == 1:
		if prime(a + b):
			print('YES')
			continue
	print('NO')


def _try_composite(a, d, n, s):
	if pow(a, d, n) == 1:
		return False
	for i in range(s):
		if pow(a, 2 ** i * d, n) == n - 1:
			return False
	return True

def is_prime(n, _precision_for_huge_n=16):
	if n in _known_primes or n in (0, 1):
		return True
	if any((n % p == 0 for p in _known_primes)):
		return False
	(d, s) = (n - 1, 0)
	while not d % 2:
		(d, s) = (d >> 1, s + 1)
	if n < 1373653:
		return not any((_try_composite(a, d, n, s) for a in (2, 3)))
	if n < 25326001:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5)))
	if n < 118670087467:
		if n == 3215031751:
			return False
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7)))
	if n < 2152302898747:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11)))
	if n < 3474749660383:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13)))
	if n < 341550071728321:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17)))
	return not any((_try_composite(a, d, n, s) for a in _known_primes[:_precision_for_huge_n]))
_known_primes = [2, 3]
_known_primes += [x for x in range(5, 1000, 2) if is_prime(x)]

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

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

def li():
	return list(mi())
t = ii()
for i in range(t):
	(a, b) = mi()
	area = (a - b) * (a + b)
	if is_prime(area):
		print('YES')
	else:
		print('NO')


from sys import stdin as cin

def prime(n):
	if n <= 1:
		return 0
	if n <= 3:
		return 1
	if n % 2 == 0 or n % 3 == 0:
		return 0
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return 0
		i = i + 6
	return 1

def gcd(a, b):
	if b > 0:
		return gcd(b, a % b)
	else:
		return a
n = int(cin.readline())
while n > 0:
	(a, b) = cin.readline().split()
	a = int(a)
	b = int(b)
	c1 = gcd(a, b)
	c = a ** 2 - b ** 2
	c2 = c / gcd(c1, c)
	if prime(c2) == 1:
		print('YES')
	else:
		print('NO')
	n -= 1


from math import sqrt

def prime(number):
	for i in range(2, int(sqrt(number)) + 1):
		if number % i == 0:
			return False
	return True

def squares(lst):
	a = list()
	for elem in lst:
		if elem[0] != elem[1] + 1:
			a.append('NO')
		elif not prime(elem[0] + elem[1]):
			a.append('NO')
		else:
			a.append('YES')
	return a
n = int(input())
b = list()
for i in range(n):
	z = [int(j) for j in input().split()]
	b.append(z)
print(*squares(b), sep='\n')


def isPrime(n):
	import math
	if n <= 1:
		return False
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def test_1():
	import math
	from collections import Counter
	n = list(map(int, input().split(' ')))[0]
	for i in range(n):
		(x, y) = list(map(int, input().split(' ')))
		a = x + y
		b = x - y
		ap = isPrime(a)
		if ap and b == 1:
			print('YES')
		else:
			print('NO')
test_1()


def simple(n):
	if n == 1:
		return False
	if n == 2:
		return True
	sqr = int(n ** 0.5)
	for i in range(3, sqr + 1, 2):
		if n % i == 0:
			return False
	return True
k = int(input())
for i in range(k):
	(a, b) = map(int, input().split())
	if a - b == 1 and simple(a + b):
		print('Yes')
	else:
		print('No')


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
query = int(input())
for _ in range(query):
	(a, b) = map(int, input().split())
	dif1 = a - b
	dif2 = a + b
	if isPrime(dif1) and dif2 == 1 or (isPrime(dif2) and dif1 == 1):
		print('YES')
	else:
		print('NO')


n = int(input())

def check(a):
	i = 2
	while i * i <= a:
		if a % i == 0:
			return 'NO'
		i += 1
	return 'YES'
for i in range(n):
	(a, b) = map(int, input().split())
	if a - b == 1:
		print(check(a + b))
	else:
		print('NO')


def isp(x):
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			return False
	return True
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if abs(a - b) == 1 and isp(a + b):
		print('YES')
	else:
		print('NO')


import math

def isprime(x):
	for i in range(2, min(x, math.ceil(math.sqrt(x)) + 1)):
		if x % i == 0:
			return 0
	return 1
t = int(input())
for _ in range(t):
	(a, b) = [int(i) for i in input().split()]
	if a - b == 1 and isprime(a + b):
		print('YES')
	else:
		print('NO')


primes = [2, 3, 5, 7, 11]

def gen_primes(limit):
	global primes
	for possiblePrime in range(primes[-1] + 1, int(limit ** 0.5) + 1):
		isPrime = True
		for num in primes:
			if num > int(possiblePrime ** 0.5):
				break
			if possiblePrime % num == 0:
				isPrime = False
				break
		if isPrime:
			primes.append(possiblePrime)
	return primes

def check(n):
	for p in primes:
		if p > int(n ** 0.5):
			break
		if n % p == 0:
			return False
	return True

def check(n):
	if n == 2:
		return True
	if n == 3:
		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
t = int(input())
pp = [tuple(map(int, input().split())) for i in range(t)]
for t in pp:
	(a, b) = t
	d = a - b
	print('NO' if d > 1 or not check(2 * b + 1) else 'YES')


import math
t = int(input())

def IsPrime(x):
	k = int(math.sqrt(x) + 1)
	for i in range(2, k):
		if x % i == 0:
			return 0
	return 1
for T in range(t):
	(a, b) = map(int, input().split())
	if a < b:
		swap(a, b)
	if a - b != 1:
		print('NO')
	elif IsPrime(a + b):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	n = a + b
	f = a - b > 1
	i = 2
	while i * i <= n:
		f |= n % i < 1
		i += 1
	print('YNEOS'[f::2])


import math

def prime(n):
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			return False
		elif i == 2:
			i += 1
		else:
			i += 2
	return True
n = int(input())
for i in range(n):
	(n, m) = map(int, input().split())
	m += 1
	if n == m and prime(2 * m - 1):
		print('YES')
	else:
		print('NO')


t = int(input())
primes_limit = 447214
pc = [True for x in range(primes_limit)]
pc[0] = False
pc[1] = False
primes = []
primes.append(2)
for i in range(3, primes_limit, 2):
	if pc[i] == 1:
		primes.append(i)
		for k in range(i * i, primes_limit, i):
			pc[k] = False
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	yes = True
	if a - b != 1:
		yes = False
	if yes:
		apb = a + b
		is_apb_prime = True
		for p in primes:
			if not is_apb_prime or p >= apb:
				break
			is_apb_prime = is_apb_prime and apb % p != 0
		yes = yes and is_apb_prime
	print('YES' if yes else 'NO')


def check(a):
	for i in range(2, round(a ** 0.5 + 1)):
		if not a % i:
			return 0
	return 1
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a - b > 1 and a + b > 1:
		print('NO')
	else:
		print('YES' if check(a ** 2 - b ** 2) else 'NO')


n = int(input())
import math
for i in range(n):
	(a, b) = map(int, input().split())
	s = a - b
	m = a + b
	count = 0
	for i in range(1, int(math.sqrt(m) + 1)):
		if m % i == 0:
			count += 2
	if s == 1 and count == 2:
		print('YES')
	else:
		print('NO')


t = int(input())

def check_prime(n):
	if n == 2:
		return True
	elif n % 2 == 0:
		return False
	else:
		return all((n % i for i in range(3, int(n ** 0.5 + 1), 2)))
for i in range(0, t):
	(a, b) = map(int, input().split())
	if a - b == 1 and check_prime(a + b):
		print('YES')
	else:
		print('NO')


import math

def check_prime(square):
	num = square[0] + square[1]
	if num < 2:
		return False
	elif num % 2 == 0:
		return False
	max = math.ceil(math.sqrt(num))
	for i in range(3, max + 1, 2):
		if num % i == 0:
			return False
	return True
t = int(input())
for s in range(t):
	squares = [int(i) for i in input().split()]
	if squares[0] - squares[1] == 1 and check_prime(squares):
		print('YES')
	else:
		print('NO')


from math import sqrt
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	f = 0
	for i in range(2, int(sqrt(a + b)) + 1):
		if (a + b) % i == 0:
			f = 1
			break
	if f == 0 and a - b == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
import math
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
	else:
		l = 2 * a - 1
		p = 0
		for k in range(2, int(math.sqrt(l)) + 1):
			if l % k == 0:
				print('NO')
				p = 1
				break
		if p == 0:
			print('YES')


import math
t = int(input())
for k1 in range(t):
	(a, b) = map(int, input().rstrip().split())
	condition = True
	if a - b == 1:
		c = a + b
		if c == 2 or c == 3:
			print('YES')
		if c != 2 and c != 3:
			for i in range(2, math.floor(math.sqrt(c)) + 1):
				if c % i == 0:
					condition = False
					break
			if condition:
				print('YES')
			if not condition:
				print('NO')
	if a - b != 1:
		print('NO')


import math
MAX = 100000

def multiply(x, res, res_size):
	carry = 0
	for i in range(res_size):
		prod = res[i] * x + carry
		res[i] = prod % 10
		carry = prod // 10
	while carry:
		res[res_size] = carry % 10
		carry = carry // 10
		res_size += 1
	return res_size

def power(x, n):
	res = [0 for i in range(MAX)]
	res_size = 0
	temp = x
	ans = []
	while temp != 0:
		res[res_size] = temp % 10
		res_size += 1
		temp = temp // 10
	for i in range(2, n + 1):
		res_size = multiply(x, res, res_size)
	for i in range(res_size - 1, -1, -1):
		ans.append(str(res[i]))
	return int(''.join(ans))

def _try_composite(a, d, n, s):
	if pow(a, d, n) == 1:
		return False
	for i in range(s):
		if pow(a, 2 ** i * d, n) == n - 1:
			return False
	return True

def is_prime(n, _precision_for_huge_n=16):
	if n in _known_primes or n in (0, 1):
		return True
	if any((n % p == 0 for p in _known_primes)):
		return False
	(d, s) = (n - 1, 0)
	while not d % 2:
		(d, s) = (d >> 1, s + 1)
	if n < 1373653:
		return not any((_try_composite(a, d, n, s) for a in (2, 3)))
	if n < 25326001:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5)))
	if n < 118670087467:
		if n == 3215031751:
			return False
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7)))
	if n < 2152302898747:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11)))
	if n < 3474749660383:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13)))
	if n < 341550071728321:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17)))
	return not any((_try_composite(a, d, n, s) for a in _known_primes[:_precision_for_huge_n]))
_known_primes = [2, 3]
_known_primes += [x for x in range(5, 1000, 2) if is_prime(x)]
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().strip().split())
	temp = power(a, 2) - power(b, 2)
	if is_prime(temp):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
		continue
	c = a + b
	for t in range(2, int(c ** 0.5) + 1):
		if c % t == 0:
			print('NO')
			break
	else:
		print('YES')


import sys
n = int(sys.stdin.readline().strip())
for i in range(n):
	(a, b) = [int(x) for x in sys.stdin.readline().strip().split(' ') if x]
	res1 = a + b
	res2 = a - b
	d = 2
	cnt = 0
	if res2 != 1:
		print('NO')
	else:
		while d * d <= res1:
			if res1 % d == 0:
				cnt = -1
				print('NO')
				break
			d += 1
		if cnt == 0:
			print('YES')


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

def main():
	n = int(input())
	array = [list(map(int, input().split(' '))) for _ in range(n)]
	answer = []
	for el in array:
		if el[0] - el[1] != 1:
			answer.append('NO')
		elif is_prime(2 * el[1] + 1):
			answer.append('YES')
		else:
			answer.append('NO')
	for i in answer:
		print(i)
main()


import math

def is_prime(n):
	bound = int(math.sqrt(n + 1) + 1)
	for k in range(2, bound):
		if n % k == 0:
			return False
	return True

def solve():
	(a, b) = (int(x) for x in input().split())
	if a - b != 1:
		print('NO')
		return
	if is_prime(a + b):
		print('YES')
	else:
		print('NO')
num_tests = int(input())
for _ in range(num_tests):
	solve()


n = int(input())
from math import sqrt
from itertools import count, islice

def isPrime(n):
	return n > 1 and all((n % i for i in islice(count(2), int(sqrt(n) - 1))))
while n:
	l = input().split()
	k = int(l[0]) - int(l[1])
	k1 = int(l[0]) + int(l[1])
	if k == 1 and isPrime(k1):
		print('YES')
	else:
		print('NO')
	n -= 1


import math
n = int(input())

def isPrime(n):
	if n is 1:
		return False
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			return False
		i += 1
	return True
for i in range(n):
	(a, b) = map(int, input().split())
	if a - b > 1:
		print('NO')
		continue
	print('YES') if isPrime(a + b) else print('NO')


n = int(input())
ans = ['YES' for i in range(n)]
for i in range(n):
	(a, b) = map(int, input().split())
	if a - b == 1:
		t = 1
		while t ** 2 < a + b:
			t += 1
			if (a + b) % t == 0:
				ans[i] = 'No'
	else:
		ans[i] = 'No'
for i in range(n):
	print(ans[i])


import random
_mrpt_num_trials = 5

def is_probable_prime(n):
	assert n >= 2
	if n == 2:
		return True
	if n % 2 == 0:
		return False
	s = 0
	d = n - 1
	while True:
		(quotient, remainder) = divmod(d, 2)
		if remainder == 1:
			break
		s += 1
		d = quotient
	assert 2 ** s * d == n - 1

	def try_composite(a):
		if pow(a, d, n) == 1:
			return False
		for i in range(s):
			if pow(a, 2 ** i * d, n) == n - 1:
				return False
		return True
	for i in range(_mrpt_num_trials):
		a = random.randrange(2, n)
		if try_composite(a):
			return False
	return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	diff = a * a - b * b
	if is_probable_prime(diff):
		print('YES')
	else:
		print('NO')


def prime(n):
	if n == 1:
		return 'NO'
	else:
		p = 2
		cnt = 0
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				cnt = 1
				break
		if cnt == 0:
			return 'YES'
		else:
			return 'NO'
t = int(input())
for i in range(t):
	(N, M) = map(int, input().split())
	if abs(N - M) == 1:
		print(prime(N + M))
	else:
		print('NO')


n = int(input())
for i in range(0, n):
	(a, b) = map(int, input().split())
	if a - b > 1:
		print('NO')
	else:
		a += b
		i = 2
		while i * i <= a:
			if a % i == 0:
				print('NO')
				break
			i += 1
		else:
			print('YES')


import sys
numcases = int(sys.stdin.readline()[0])

def isPrime(number):
	tester = int(number ** (1 / 2) + 1)
	for g in range(2, tester):
		if number % g == 0:
			return False
	return True

def calcArea(a, b):
	area1 = a * (a - b)
	area2 = b * (a - b)
	return area1 + area2

def getFactors(p):
	for x in range(1, p):
		if p % x == 0:
			return False
answers = []
for p in range(numcases):
	currline = sys.stdin.readline().split()
	override = False
	if len(currline[0]) < 20:
		a = int(currline[0])
	elif currline[0][0:len(currline[0]) - 2] != currline[1][0:len(currline[1]) - 2]:
		a = 10000000000000000000000
	elif (int(currline[0][len(currline[0]) - 1]) - int(currline[1][len(currline[1]) - 1]) == 1) | (int(currline[0][len(currline[0]) - 1]) - int(currline[1][len(currline[1]) - 1]) == -1):
		override = True
	else:
		a = 10000000000000000000000
	b = int(currline[1])
	if override == False:
		if a - b != 1:
			isPrimers = False
		elif isPrime(2 * b + 1):
			isPrimers = True
		else:
			isPrimers = False
	elif isPrime(2 * b + 1):
		isPrimers = True
	else:
		isPrimers = False
	if isPrimers:
		answers.append('YES')
	else:
		answers.append('NO')
for t in range(len(answers)):
	print(answers[t])


import sys, math, io, os, time, itertools, collections
mod = 10 ** 9 + 7
sys.setrecursionlimit(10000)
i = sys.stdin.readline
p = sys.stdout.write
global start, end

def decompose(k):
	s = 0
	while True:
		if k % 2 == 1:
			return (s, k)
		k = k // 2
		s += 1

def miller(n):
	check = []
	if n == 2:
		return True
	if n < 2047:
		check = [2]
	elif n < 1373653:
		check = [2, 3]
	elif n < 9080191:
		check = [31, 73]
	elif n < 25326001:
		check = [2, 3, 5]
	elif n < 3215031751:
		check = [2, 3, 5, 7]
	elif n < 4759123141:
		check = [2, 7, 61]
	elif n < 1122004669633:
		check = [2, 13, 23]
	else:
		return True
	(s, d) = decompose(n - 1)
	for a in check:
		x = pow(a, d)
		if x % n == 1 or x % n == n - 1:
			continue
		bool = False
		for _ in range(s - 1):
			x = x * x
			if x % n == n - 1:
				bool = True
				break
		if bool:
			continue
		return False
	return True

def is_prime(n):
	if n <= 3:
		return n > 1
	if n % 2 == 0 or n % 3 == 0:
		return False
	k = 5
	while k ** 2 <= n:
		if n % k == 0 or n % (k + 2) == 0:
			return False
		k += 6
	return True

def main():
	(a, b) = [int(k) for k in i().split()]
	if a - b == 1 and is_prime(a + b):
		p('YES\n')
	else:
		p('NO\n')
t = 1
t = int(i())
start = time.perf_counter()
for _ in range(t):
	main()
end = time.perf_counter()


def prime(x):
	if x == 1:
		return False
	ret = True
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			ret = False
	return ret
n = int(input())
for i in range(n):
	s = input().split()
	d = int(s[0]) - int(s[1])
	if d != 1:
		print('NO')
	elif prime(int(s[0]) + int(s[1])):
		print('YES')
	else:
		print('NO')


def isPrime(N):
	for i in range(2, int(N ** 0.5) + 1):
		if N % i == 0:
			return False
	return True
for i in range(int(input())):
	X = list(map(int, input().split()))
	print('YES' if X[0] - X[1] == 1 and isPrime(X[0] + X[1]) else 'NO')


import math
n = int(input())

def my_pow(a, b, mod):
	if b == 1:
		return a
	if b == 0:
		return 1
	halfRet = my_pow(a, b >> 1, mod)
	if b % 2 == 1:
		return halfRet * a % mod * halfRet % mod
	else:
		return halfRet * halfRet % mod

def checkPrim(a):
	check_list = [2, 3, 5, 7, 11]
	for i in check_list:
		if i != a:
			if 1 != my_pow(i, a - 1, a):
				return False
	return True
for i in range(n):
	[a, b] = map(int, input().split())
	if a - b != 1:
		print('NO')
	elif checkPrim(a + b):
		print('YES')
	else:
		print('NO')


def isPrime(n):
	if n <= 1:
		return 'NO'
	if n <= 3:
		return 'YES'
	if n % 2 == 0 or n % 3 == 0:
		return 'NO'
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return 'NO'
		i = i + 6
	return 'YES'
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
	else:
		x = a + b
		print(isPrime(x))


from sys import stdin
t = int(input())

def is_prime(n):
	d = 2
	while d * d <= n:
		if n % d == 0:
			return False
		d += 1
	return n > 1
for _ in range(t):
	(a, b) = map(int, stdin.readline().split())
	if a - b != 1:
		print('NO')
	elif is_prime(a + b):
		print('YES')
	else:
		print('NO')


n = int(input())
fin = []
for i in range(n):
	lis = list(map(int, input().split()))
	fin.append(lis)

def pchecker(number):
	for i in range(2, int(number ** (1 / 2)) + 1):
		if number % i == 0:
			return False
	else:
		return True
for i in fin:
	if i[0] - i[1] == 1 and pchecker(i[0] + i[1]) == True:
		print('YES')
	else:
		print('NO')
pchecker(13)


import math
for x in range(int(input())):
	(h, m) = list(map(int, input().split()))
	if h - m == 1:
		r = 'YES'
		for i in range(2, int(math.sqrt(h + m)) + 1):
			if (h + m) % i == 0:
				r = 'NO'
	else:
		r = 'NO'
	print(r)


from collections import defaultdict
from math import log2, floor, sqrt
from pprint import pprint
mod = pow(10, 9) + 7

def isprime(n):
	for i in range(2, floor(sqrt(n)) + 1):
		if n % i == 0:
			return 0
	return 1

def fun(b, a):
	if b - a == 1:
		if isprime(b + a):
			print('YES')
			return
	print('NO')
	return
for i in range(int(input())):
	(b, a) = map(int, input().split())
	fun(b, a)


t = int(input())
for i in range(t):
	l = input().split()
	if int(l[0]) - int(l[1]) == 1:
		flag = 0
		for j in range(2, int(pow(int(l[0]) + int(l[1]), 0.5)) + 1):
			if (int(l[0]) + int(l[1])) % j == 0:
				flag = 1
				break
		if flag == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	f = 1
	n = a + b
	i = 2
	while i * i <= n:
		if n % i == 0:
			break
		i += 1
	else:
		f = 0
	print('YNEOS'[a - b > 1 or f::2])


test_cases = int(input())
for _ in range(test_cases):
	(a, b) = list(map(int, input().strip().split()))
	first = 0
	second = 0
	resulting_area = a * a - b * b
	if (resulting_area + 1) % 2 == 0:
		first = int((resulting_area - 1) / 2)
		second = int((resulting_area + 1) / 2)
		if second - first == 1:
			test = first + second
			max_bound = int(test ** 0.5) + 2
			if test == 1 or test == 2 or test == 3 or (test == 5) or (test == 7) or (test == 11) or (test == 13) or (test == 17):
				print('YES')
			elif (test % 2 and test % 3 and test % 5 and test % 7 and test % 11 and test % 13) == False:
				print('NO')
			elif all((test % (x - 1) and test % (x + 1) for x in range(18, max_bound, 6))):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


def is_prime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True
t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	if a - b > 1:
		print('NO')
	elif is_prime(b * b - a * a):
		print('YES')
	else:
		print('NO')


from math import *

def prmfct(n):
	li = []
	while n % 2 == 0:
		li.append(2)
		n = n / 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			li.append(int(i))
			n = int(n / i)
	if n > 2:
		li.append(int(n))
	return li
t = int(input())
for i in range(t):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if abs(a - b) == 1 and len(prmfct(a + b)) == 1:
		print('YES')
	else:
		print('NO')


import math
from math import sqrt
from itertools import count, islice

def isPrime(n):
	return n > 1 and all((n % i for i in islice(count(2), int(sqrt(n) - 1))))
n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = a[0]
	c = a[1]
	if b - c == 1:
		if isPrime(b + c):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def is_prime(n):
	if n == 1:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
c = int(input())
for i in range(c):
	(a, b) = [int(x) for x in input().split()]
	if a - b == 1 and is_prime(a + b):
		print('YES')
	elif a + b == 1 and is_prime(a - b):
		print('YES')
	else:
		print('NO')


def isprime(n):
	if n == 2 or n == 3:
		return True
	elif n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
for _ in range(int(input())):
	(a, b) = map(int, input().strip().split())
	if a - b != 1:
		print('NO')
	elif isprime(a + b):
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	flag = True
	if a - b == 1:
		c = a + b
		for i in range(2, int(c ** (1 / 2)) + 1):
			if c % i == 0:
				print('NO')
				flag = False
				break
			else:
				pass
		if flag:
			print('YES')
	elif a + b == 1:
		c = a - b
		for i in range(2, int(c ** (1 / 2))):
			if c % i == 0:
				print('NO')
				flag = False
				break
		if flag:
			print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a - b == 1:
		c = a + b
		for d in range(2, int(c ** 0.5) + 1):
			if c % d == 0:
				print('NO')
				break
		else:
			print('YES')
	else:
		print('NO')


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	if x - y == 1 and isPrime(x + y):
		print('YES')
	else:
		print('NO')


def check_prime(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
t = int(input())
for tnum in range(t):
	(a, b) = map(int, input().split())
	if a != b + 1:
		print('NO')
	else:
		print('YES' if check_prime(a + b) else 'NO')


import math
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	d = a - b
	u = True
	if d > 1:
		print('NO')
		continue
	else:
		d = a + b
		for x in range(2, max(2, int(math.sqrt(d))) + 1):
			if d % x == 0:
				u = False
				break
		if u:
			print('YES')
		else:
			print('NO')


import math
n = int(input())

def checkPrim(a):
	i = 2
	while i * i <= a:
		if a % i == 0:
			return False
		i += 1
	return True
for i in range(n):
	[a, b] = map(int, input().split())
	if a - b != 1:
		print('NO')
	elif checkPrim(a + b):
		print('YES')
	else:
		print('NO')


import math
t = int(input())

def isPrime(num):
	if num < 2:
		print('NO')
		return
	if num == 2 or num == 3:
		print('YES')
		return
	if num % 2 == 0 or num % 3 == 0:
		print('NO')
		return
	i = 5
	jump = 2
	while i * i <= num:
		if num % i == 0:
			print('NO')
			return
		i += jump
		jump = 6 - jump
	print('YES')
	return
for i in range(t):
	(a, b) = map(int, input().split(' '))
	if a - b == 1:
		isPrime(a * a - b * b)
	else:
		print('NO')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	prime = 1
	i = 2
	while i * i <= a + b:
		prime = 0 if a - b != 1 or (a + b) % i == 0 else 1
		if not prime:
			break
		i += 1
	print('YES' if prime else 'NO')


import math

def isPrime(x):
	a = True
	index = 2
	while a == True and index <= math.floor(math.sqrt(x)):
		if x % index == 0 and x != index:
			a = False
		index += 1
	return a
n = int(input())
t = []
for i in range(n):
	(x, y) = list(map(int, input().split()))
	t.append([x, y])
for g in t:
	if g[0] - g[1] == 1 and isPrime(g[0] + g[1]):
		print('YES')
	else:
		print('NO')


from math import sqrt
n = int(input())

def is_simple(x):
	if x % 2 == 0:
		return False
	k = int(sqrt(x))
	for j in range(3, k + 1, 2):
		if x % j == 0:
			return False
	return True
for i in range(n):
	[a, b] = map(int, input().split())
	num = a + b
	if a - b == 1:
		if is_simple(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	p = a - b
	q = a + b
	if p > 1 and q > 1:
		print('no')
	elif isPrime(max(p, q)):
		print('yes')
	else:
		print('no')


def is_prime(n):
	if n == 2 or n == 3:
		return True
	if n < 2 or n % 2 == 0:
		return False
	if n < 9:
		return True
	if n % 3 == 0:
		return False
	r = int(n ** 0.5)
	f = 5
	while f <= r:
		if n % f == 0:
			return False
		if n % (f + 2) == 0:
			return False
		f += 6
	return True
n = int(input())
for lflkf in range(n):
	inp = input().split()
	a = int(inp[0])
	b = int(inp[1])
	if a - b > 1:
		print('NO')
	elif a - b == 1 and is_prime(a * a - b * b):
		print('YES')
	else:
		print('NO')


import math
n = int(input())
for i in range(n):
	f = 0
	(a, b) = map(int, input().split())
	if a - b == 1:
		c = a + b
		d = math.sqrt(c)
		d = int(d)
		for j in range(3, d + 1, 2):
			if c % j == 0:
				f = 1
				break
	else:
		f = 1
	if f == 1:
		print('NO')
	else:
		print('YES')


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	prime = True
	min_n = min(a, b)
	max_n = max(a, b)
	if max_n - min_n != 1:
		prime = False
	else:
		for i in range(2, math.ceil((a + b) ** 0.5) + 1):
			if (a + b) % i == 0:
				prime = False
				break
	if prime:
		print('YES')
	else:
		print('NO')


t = int(input())

def divider(n):
	i = 2
	j = 0
	while i ** 2 <= n and j != 1:
		if n % i == 0:
			j = 1
		i += 1
	if j == 1:
		return False
	else:
		return True
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a - b == 1 and divider(a + b):
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	X = list(map(int, input().split()))
	print('YES' if X[0] - X[1] == 1 and (not any(((X[0] + X[1]) % i == 0 for i in range(2, int((X[0] + X[1]) ** 0.5) + 1)))) else 'NO')


import math
from math import sqrt
from itertools import count, islice

def is_prime(n):
	return n > 1 and all((n % i for i in islice(count(2), int(sqrt(n) - 1))))
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	d = a ** 2 - b ** 2
	if a - b == 1 and is_prime(a + b):
		print('YES')
	else:
		print('NO')


import math

def find_prime(n):
	flag = True
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		if n % i == 0:
			flag = False
			break
	return flag
t = int(input())
i = 0
op = []
while i < t:
	(a, b) = map(int, input().split(' '))
	if a - b == 1:
		if find_prime(a + b):
			op.append('YES')
		else:
			op.append('NO')
	else:
		op.append('NO')
	i += 1
j = 0
while j < t:
	print(op[j])
	j += 1


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	if n - m != 1:
		print('NO')
	elif isPrime(n + m):
		print('YES')
	else:
		print('NO')


import sys
from math import *
n = int(sys.stdin.readline().strip())

def prime(a, b):
	c = True
	for i in range(2, floor(sqrt(a + b)) + 1):
		if (a + b) % i == 0:
			c = False
	return c and a - b == 1
for i in range(n):
	(a, b) = [int(x) for x in sys.stdin.readline().strip().split(' ') if x]
	if prime(a, b):
		print('YES')
	else:
		print('NO')


n = int(input())

def primc(io):
	if io == 1:
		return True
	for i in range(2, int(io ** 0.5) + 1):
		if io % i == 0:
			return False
	return True
for i in range(n):
	a = input().split(' ')
	if int(a[0]) - int(a[1]) == 1:
		o = int(a[0]) + int(a[1])
		oi = int(a[0]) - int(a[1])
		an = primc(o * oi)
		if an:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


n = int(input())
for i in range(0, n):
	k = 0
	(a, b) = map(int, input().split())
	if a - b != 1:
		k = 1
	if a == b + 1:
		x = 2 * b + 1
		u = int(x ** 0.5)
		for i in range(2, u + 1):
			if x % i == 0:
				k = 1
	if k == 0:
		print('YES')
	else:
		print('NO')


import collections
from functools import cmp_to_key

def readnums():
	return list(map(lambda x: int(x), input().split(' ')))
MAXN = int(5 * 100000.0)
prime = set((i for i in range(2, int(MAXN + 1))))

def sieve(n):
	global MAXN
	p = 2
	while p * p <= n:
		if p in prime:
			for i in range(p * 2, n + 1, p):
				if i in prime:
					prime.remove(i)
		p += 1

def isprime(n):
	global prime
	if n in prime:
		return True
	for i in prime:
		if n % i == 0:
			return False
	return True
sieve(MAXN)
t = int(input())
for i in range(t):
	(a, b) = readnums()
	if a - b == 1 and isprime(a + b):
		print('YES')
	else:
		print('NO')


import math

def isPrime(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if not n % i:
			return False
	return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if isPrime(a + b) and a - b == 1:
		print('YES')
	else:
		print('NO')


import math

def isPrime(num):
	if num < 2:
		return False
	else:
		for i in range(2, int(math.sqrt(num)) + 1):
			if num % i == 0:
				return False
		return True

def main():
	n = int(input())
	for i in range(n):
		(a, b) = map(int, input().split())
		if a - b == 1 and isPrime(a + b):
			print('YES')
		else:
			print('NO')
main()


from math import sqrt

def isPrime(n):
	if n % 2 == 0:
		return False
	else:
		for i in range(3, int(sqrt(n)) + 1, 2):
			if n % i == 0:
				return False
	return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
	elif isPrime(a + b):
		print('YES')
	else:
		print('NO')


import math as m

def f(a):
	if a == 2:
		return True
	for i in range(2, round(m.sqrt(a)) + 1):
		if a % i == 0:
			return False
	return True
t = int(input())
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a - b == 1 and f(a + b):
		print('YES')
	else:
		print('NO')


def ch(a):
	if a == 1:
		return False
	if a == 2:
		return True
	for i in range(2, int(a ** 0.5) + 2):
		if not a % i:
			return False
	return True
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a - b == 1 and ch(a + b):
		print('YES')
	else:
		print('NO')


n = int(input())

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True
for _ in range(n):
	(x, y) = [int(x) for x in input().split()]
	if x - y > 1:
		print('NO')
		continue
	if isprime(x + y):
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for w in range(t):
	(a, b) = (int(i) for i in input().split())
	if a - b > 1:
		print('NO')
	else:
		n = a + b
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				n = -1
				break
		if n == -1:
			print('NO')
		else:
			print('YES')


import math

def isPrime(n):
	flag = True
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		if n % i == 0:
			flag = False
			break
	return flag
n = int(input())
t = []
for i in range(n):
	(x, y) = list(map(int, input().split()))
	t.append([x, y])
for g in t:
	if g[0] - g[1] == 1 and isPrime(g[0] + g[1]):
		print('YES')
	else:
		print('NO')


def isprime(n):
	if n == 2:
		return True
	if n == 3:
		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
t = int(input())
for x in range(t):
	(a, b) = list(map(int, input().strip().split()))
	if a - b == 1:
		if isprime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from sys import stdin

def main():
	T = int(input())
	AB = [tuple(map(int, input().split())) for _ in [0] * T]
	for (a, b) in AB:
		if a - b > 1:
			print('NO')
		elif is_prime(a + b):
			print('YES')
		else:
			print('NO')

def is_prime(n):
	if n == 2:
		return True
	if n < 2 or not n & 1:
		return False
	for i in range(3, n, 2):
		if not n % i:
			return False
		if i * i >= n:
			break
	return True
input = lambda : stdin.readline()
main()


from math import *
t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split(' ')]
	if a - b != 1:
		print('NO')
	else:
		can = False
		for i in range(2, min(a + b, int(sqrt(a + b) + 1))):
			can |= (a + b) % i == 0
		print('NO' if can else 'YES')


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	v = a + b
	flag = 0
	if a - b != 1:
		print('NO')
	else:
		for i in range(2, int(v ** 0.5) + 1):
			if v % i == 0:
				flag = 1
				break
		if flag == 0:
			print('YES')
		else:
			print('NO')


n = int(input())
while n:
	n = n - 1
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	flag = True
	for i in range(2, a + b):
		if i * i > a + b:
			break
		if (a + b) % i == 0:
			flag = False
			break
	if flag and a - b == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	S = N - K
	L = N + K
	if S != 1:
		print('NO')
	else:
		FLAG = True
		for i in range(2, int(pow(L, 1 / 2)) + 1):
			if L % i == 0:
				FLAG = False
				break
		if FLAG == True:
			print('YES')
		else:
			print('NO')


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(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

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

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

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

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

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

def ws(s):
	sys.stdout.write(s + '\n')

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def fastPrintNextLines(a):
	print('\n'.join(map(str, a)))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = 1

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True
t = int(input())
for _ in range(t):
	(a, b) = li()
	if a - b == 1:
		x = 2 * b + 1
		if isPrime(x):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from math import sqrt

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

def isprime(x):
	for i in range(2, int(1 + sqrt(x))):
		if x % i == 0:
			return False
	return True
n = readline()[0]
arr = []
for i in range(n):
	arr.append(readline())
for (a, b) in arr:
	if a - b > 1:
		print('NO')
	elif isprime(a + b):
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	p = False
	if a - b == 1:
		(c, k) = (a + b, 3)
		if c % 2 == 0:
			p = True
		while k - 1 < int(c ** (1 / 2)) and (not p):
			if c % k == 0:
				p = True
			else:
				k += 2
		if not p:
			print('Yes')
		else:
			print('No')
	else:
		print('No')


import sys
import math

def rec(c):
	k = 2
	flag = 1
	while k * k <= c:
		if c % k == 0:
			flag = 0
			break
		elif k == 2:
			k = 3
		else:
			k += 2
	return flag
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a - b == 1:
		t = a + b
		if rec(t):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
answer = ['Yes'] * t
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a - b == 1:
		j = 1
		while j * j < a + b:
			j = j + 1
			if (a + b) % j == 0:
				answer[i] = 'No'
	else:
		answer[i] = 'No'
for i in range(t):
	print(answer[i])


import sys

def isprime(x):
	import math
	if x == 1:
		return True
	for i in range(2, math.ceil(math.sqrt(x)) + 1):
		if x % i == 0:
			return False
	return True
cin = sys.stdin
T = int(next(cin))
for _ in range(T):
	(n, m) = map(int, next(cin).split())
	if n - m == 1 and isprime(n + m):
		print('YES')
	else:
		print('NO')


for s in [*open(0)][1:]:
	(a, b) = map(int, s.split())
	x = 2
	y = a + b
	while x * x <= y:
		if y % x == 0:
			break
		x += 1
	print('YNEOS'[x * x <= y or a - b > 1::2])


import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

def instr():
	s = input()
	return list(s[:len(s)])

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

def is_prime(n):
	limit = int(sqrt(n) + 1)
	if n == 2:
		return True
	for i in range(2, limit + 1):
		if n % i == 0:
			return False
	return True
t = inp()
for _ in range(t):
	(a, b) = invr()
	if a - b == 1 and is_prime(a + b):
		print('YES')
	else:
		print('NO')


t = int(input())

def f(n):
	if n % 2 == 0:
		return False
	i = 3
	while i * i <= n:
		if n % i == 0:
			return False
		i += 2
	return True
for _ in range(t):
	(a, b) = map(int, input().split())
	if a - b == 1:
		if f(2 * b + 1):
			print('YES')
			continue
	print('NO')


t = int(input())
for i in range(0, t):
	(sa, sb) = [int(x) for x in input().split(' ')]
	f = int(0)
	if sa - sb == 1:
		k = sa + sb
		for j in range(2, int(k ** 0.5) + 1):
			if k % j == 0:
				f = 1
				break
		if f == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import math

def is_prime(x):
	if x < 2:
		return False
	else:
		for n in range(2, int(math.sqrt(x)) + 1):
			if x % n == 0:
				return False
		return True
t = int(input())
for i in range(t):
	(a, b) = tuple(map(int, input().split()))
	if a - b == 1 and is_prime(a + b):
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	divisors = 0
	for j in range(1, int(math.sqrt(a + b)) + 1):
		if (a + b) % j == 0:
			divisors += 2
	if divisors == 2 and a - b == 1:
		print('YES')
	else:
		print('NO')


def isPrime(a):
	if a % 2 == 0:
		return False
	limit = int(a ** 0.5)
	for i in range(3, limit + 1, 2):
		if a % i == 0:
			return False
	return True
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a == b + 1:
		if isPrime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from math import sqrt
from itertools import count, islice
t = int(input())

def is_prime(n):
	return n > 1 and all((n % i for i in islice(count(2), int(sqrt(n) - 1))))
s = []
for i in range(t):
	(a, b) = [int(ig) for ig in input().split()]
	c = a ** 2 - b ** 2
	if a - b != 1:
		s.append('NO')
	else:
		s.append('YES' if is_prime(b + a) else 'NO')
for f in s:
	print(f)


n = int(input())

def isprime(n):
	if n == 1:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
for i in range(n):
	(a, b) = map(int, input().split())
	m = a - b
	p = a + b
	if m == 1 and isprime(p):
		print('YES')
	else:
		print('NO')


import math

def is_prime_number(x):
	for i in range(2, int(math.sqrt(x)) + 2):
		if x % i == 0:
			return False
	return True
t = int(input())
a = []
b = []
res = []
for i in range(t):
	l = input().split()
	a.append(int(l[0]))
	b.append(int(l[1]))
	if a[i] - b[i] == 1 and is_prime_number(a[i] + b[i]):
		res.append('YES')
	else:
		res.append('NO')
for e in res:
	print(e)


def prime(x):
	if x < 2:
		return 0
	i = 2
	while i * i <= x:
		if x % i == 0:
			return 0
		i += 1
	return 1
t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split(' '))
	if n - m == 1:
		if prime(n * n - m * m):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def prime(n):
	if n == 1:
		return 0
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 0
		i += 1
	return 1
t = int(input())
while t != 0:
	(a, b) = map(int, input().split())
	if a - b == 1 and prime(a + b):
		print('YES')
	else:
		print('NO')
	t -= 1


from math import ceil, sqrt

def is_prime(n):
	for i in [2] + [j for j in range(3, int(sqrt(n)) + 2, 2)]:
		if n % i == 0:
			return False
	return True
n = int(input())
for _ in range(n):
	(a, b) = [int(i) for i in input().split()]
	prime = a - b == 1 and is_prime(2 * a - 1)
	print('YES' if prime else 'NO')


def isPrime(n, k=1000):
	from random import randint
	if n < 2:
		return False
	for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]:
		if n % p == 0:
			return n == p
	(s, d) = (0, n - 1)
	while d % 2 == 0:
		(s, d) = (s + 1, d / 2)
	for i in range(k):
		x = pow(randint(2, n - 1), int(d), n)
		if x == 1 or x == n - 1:
			continue
		for r in range(1, s):
			x = x * x % n
			if x == 1:
				return False
			if x == n - 1:
				break
		else:
			return False
	return True
t = int(input())
for i in range(0, t):
	v = [int(x) for x in input().split()]
	a = int(v[0])
	b = int(v[1])
	n = a * a - b * b
	if isPrime(n):
		print('YES')
	else:
		print('NO')


import sys

def is_prime(x):
	if x in [1, 2, 3]:
		return True
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			return False
	return True
n = int(next(sys.stdin))
for _ in range(n):
	(a, b) = map(int, next(sys.stdin).split())
	if a - b == 1 and is_prime(2 * a - 1):
		print('YES')
	else:
		print('NO')


import random

def MillerRabinPrimalityTest(number):
	if number == 2:
		return True
	elif number == 1 or number % 2 == 0:
		return False
	oddPartOfNumber = number - 1
	timesTwoDividNumber = 0
	while oddPartOfNumber % 2 == 0:
		oddPartOfNumber = oddPartOfNumber // 2
		timesTwoDividNumber = timesTwoDividNumber + 1
	for time in range(3):
		while True:
			randomNumber = random.randint(2, number) - 1
			if randomNumber != 0 and randomNumber != 1:
				break
		randomNumberWithPower = pow(randomNumber, oddPartOfNumber, number)
		if randomNumberWithPower != 1 and randomNumberWithPower != number - 1:
			iterationNumber = 1
			while iterationNumber <= timesTwoDividNumber - 1 and randomNumberWithPower != number - 1:
				randomNumberWithPower = pow(randomNumberWithPower, 2, number)
				iterationNumber = iterationNumber + 1
			if randomNumberWithPower != number - 1:
				return False
	return True
cases = int(input())
for case in range(cases):
	(a, b) = map(int, input().split())
	t = MillerRabinPrimalityTest(a ** 2 - b ** 2)
	if t:
		print('YES')
	else:
		print('NO')


import sys
from math import sqrt

def isPrime(x):
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			return False
	return True

def isDiffSqPrime(a, b):
	return a - b == 1 and isPrime(2 * a - 1)
t = int(input())
cases = sys.stdin.readlines()
cases = [x.rstrip().split(' ') for x in cases]
for case in cases:
	(a, b) = (int(case[0]), int(case[1]))
	ans = 'YES' if isDiffSqPrime(a, b) else 'NO'
	print(ans)


import math

def check(a):
	if a == 0:
		return False
	elif a == 1:
		return False
	elif a == 2:
		return True
	for i in range(2, int(math.sqrt(a)) + 1):
		if a % i == 0:
			return False
	return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if abs(a - b) != 1:
		print('NO')
	elif check(a + b) == True:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
		continue
	else:
		flag = True
		m = a + b
		j = 2
		while j * j <= m:
			if m % j == 0:
				flag = False
				break
			j += 1
		if flag:
			print('YES')
		else:
			print('NO')


import math

def check_prime(n):
	for j in range(math.floor(math.sqrt(n)), 1, -1):
		if n % j == 0:
			return 0
	return 1
t = int(input())
array = []
while t > 0:
	array.append(list(map(int, input().split())))
	t -= 1
for i in array:
	if i[0] - i[1] != 1:
		print('NO')
	elif check_prime(i[0] + i[1]):
		print('YES')
	else:
		print('NO')


from math import sqrt

def era(n):
	i = 2
	limit = int(sqrt(n)) + 1
	while i < limit:
		if n % i == 0:
			return True
		i += 1
	return False
t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	c = a + b
	z = era(c)
	if a - b == 1 and (not z):
		print('YES')
	else:
		print('NO')


import math

def estpremier(n):
	if n < 7:
		if n in (2, 3, 5):
			return True
		else:
			return False
	if n & 1 == 0:
		return False
	k = 3
	r = math.sqrt(n)
	while k <= r:
		if n % k == 0:
			return False
		k += 2
	return True
sortie = []
test = 0
vartest = int(input())
for i in range(vartest):
	(var2, var3) = map(int, input().split(' '))
	test1 = var2 - var3
	test2 = var2 + var3
	if estpremier(test2) & (test1 == 1):
		print('Yes')
	else:
		print('No')


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

def isprime(n):
	if n % 2 == 0:
		return 0
	i = 3
	while i * i <= n:
		if n % i == 0:
			return 0
		i += 2
	return 1
for _ in range(int(input())):
	(x, y) = [int(a) for a in input().split()]
	if x - y != 1:
		print('NO')
	elif isprime(x + y) == 1:
		print('YES')
	else:
		print('NO')


import sys
import math
import bisect

def is_prime(n):
	for i in range(2, math.floor(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def solve(a, b):
	if a - b > 1:
		return False
	return is_prime(a + b)

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if solve(a, b):
			print('YES')
		else:
			print('NO')
main()


import random

def is_prime(n):
	if n == 2:
		return True
	if n == 1 or n & 1 == 0:
		return False
	d = n - 1 >> 1
	while d & 1 == 0:
		d >>= 1
	for k in range(100):
		a = random.randint(1, n - 1)
		t = d
		y = pow(a, t, n)
		while t != n - 1 and y != 1 and (y != n - 1):
			y = y * y % n
			t <<= 1
		if y != n - 1 and t & 1 == 0:
			return False
	return True
t = int(input())
a = [0] * t
b = [0] * t
d = [0] * t
for i in range(t):
	(a[i], b[i]) = map(int, input().split())
for i in range(t):
	d = a[i] * a[i] - b[i] * b[i]
	print('YES') if is_prime(d) else print('NO')


def is_prime(n):
	if n == 1:
		return True
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
t = int(input())
for cas in range(t):
	(a, b) = map(int, input().split())
	(n1, n2) = (a + b, a - b)
	if is_prime(n1):
		if n2 == 1:
			print('YES')
		else:
			print('NO')
	elif is_prime(n2):
		if n1 == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from math import sqrt

def isprime(x):
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			return False
	return True
t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a - b == 1:
		if isprime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	t -= 1


import math

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, round(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True
n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	if x - y > 1:
		print('NO')
	elif is_prime(x + y):
		print('YES')
	else:
		print('NO')


def primecheck(num):
	i = 2
	f = 0
	while i * i <= num:
		if num % i == 0:
			f = 1
			break
		i += 1
	return f
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	p1 = a - b
	p2 = a + b
	if p1 == 1:
		if primecheck(p2) == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from math import sqrt
from random import random
from random import randrange

def miller_rabin(n, k=10):
	if n == 2 or n == 3:
		return True
	if n == 2:
		return True
	if not n & 1:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True
n = int(input())
for i in range(n):
	(a, b) = (int(x) for x in input().split())
	s = a * a - b * b
	if not miller_rabin(s):
		print('NO')
	else:
		print('YES')


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a - b > 1:
		print('NO')
	else:
		n = a + b
		for d in range(2, int(math.sqrt(n)) + 1):
			if n % d == 0:
				print('NO')
				break
		else:
			print('YES')


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input().strip())
for gg in range(t):
	(x, y) = list(map(int, input().strip().split()))
	if abs(y - x) == 1:
		if isPrime(x + y):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import math

def isp(n):
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			return False
	return True
n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	if a - b == 1 and isp(a + b):
		print('YES')
	else:
		print('NO')


import math

def find(x):
	if x % 2 == 0 or x == 1:
		return 0
	else:
		root = int(math.sqrt(x))
		for i in range(3, root + 1, 2):
			if x % i == 0:
				return 0
	return 1
t = int(input())
for i in range(t):
	tmp = input().split()
	if find(int(tmp[0]) + int(tmp[1])) and int(tmp[0]) == int(tmp[1]) + 1:
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for _ in range(0, t):
	a = input().split(' ')
	s = int(a[0]) + int(a[1])
	flag = int(a[0]) - int(a[1]) != 1
	for i in range(2, int(math.sqrt(s)) + 1):
		if s % i == 0:
			flag = True
			break
	print('NO' if flag else 'YES')


def isPrime2(number):
	d = 2
	while d * d <= number:
		if number % d == 0:
			return False
		d += 1
	return True
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a - b == 1:
		c = a + b
		if isPrime2(c):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from math import sqrt
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a - b != 1:
		print('NO')
	else:
		c = a + b
		div = False
		for i in range(2, int(sqrt(c)) + 2):
			if c % i == 0:
				div = True
				break
		if div:
			print('NO')
		else:
			print('YES')


t = int(input())
a = []
b = []
for i in range(t):
	(aa, bb) = [int(el) for el in input().split()]
	a.append(aa)
	b.append(bb)

def prost(n):
	if n == 3:
		return True
	if n % 2 == 0:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
	return
for i in range(t):
	if a[i] - b[i] != 1:
		print('NO')
		continue
	if prost(a[i] + b[i]):
		print('YES')
	else:
		print('NO')


import math
t = int(input())

def isprime(c):
	for x in range(2, int(math.ceil(math.sqrt(c))) + 1):
		if c % x == 0:
			return False
	return True
for x in range(t):
	(a, b) = list(map(int, input().split()))
	if 1 == a - b and isprime(a + b):
		print('YES')
	else:
		print('NO')


def prime(n):
	if n == 1:
		return 1
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			return False
	return True
n = int(input())
while n:
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	if a - b == 1 and prime(a + b):
		print('Yes')
	else:
		print('No')
	n -= 1


def seive(n):
	lp = [0] * (n + 1)
	b = []
	for i in range(2, n + 1):
		if lp[i] == 0:
			b.append(i)
		for i in range(i, n + 1, i):
			lp[i] = 1
	return b
t = int(input())
z = []
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	if a - b != 1:
		print('NO')
	else:
		k = 0
		p = a + b
		if a + b == 3 or a + b == 5 or a + b == 2:
			print('YES')
		else:
			i = 2
			while i * i <= p:
				if pow(p, 1, i) == 0:
					k = 1
					print('NO')
					break
				i = i + 1
			if k == 0:
				print('YES')


def criba_eratostenes(n, s):
	multiplos = set()
	for i in range(2, n + 1):
		if i not in multiplos:
			multiplos.update(range(i * i, n + 1, i))
			if s % i == 0:
				print('NO')
				break
	else:
		print('YES')
n = int(input())
for i in range(n):
	linea = input()
	primero = int(linea[:linea.find(' ')])
	segundo = int(linea[linea.find(' '):])
	cuadrado = primero ** 2 - segundo ** 2
	p = primero - segundo
	if p == 1:
		criba_eratostenes(int(cuadrado ** (1 / 2)), cuadrado)
	else:
		print('NO')


from math import sqrt, floor

def check(n):
	for i in range(2, floor(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if a - b == 1 and check(a + b):
		print('YES')
	else:
		print('NO')


import math

def isPrime(n):
	if n == 2 or n == 3:
		return 1
	if n % 2 == 0 or n % 3 == 0 or n < 2:
		return 0
	s = int(math.sqrt(n))
	i = -1
	while i <= s:
		i = i + 6
		if n % i == 0 or n % (i + 2) == 0:
			break
	if i > s:
		return 1
	else:
		return 0
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	x = a - b
	y = a + b
	if x == 1 and isPrime(y):
		print('YES\n')
	else:
		print('NO\n')


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	area = (a + b) * (a - b)
	if a - b != 1:
		answer = False
	else:
		x = int(area ** 0.5) + 1
		numbers = [1 for _ in range(x + 1)]
		numbers[0] = 0
		numbers[1] = 0
		for i in range(2, x + 1):
			if numbers[i]:
				j = 2
				while i * j <= x:
					numbers[i * j] = 0
					j += 1
		primes = []
		for i in range(x + 1):
			if numbers[i]:
				primes.append(i)
		answer = True
		for prime in primes:
			if area % prime == 0:
				answer = False
				break
	if answer:
		print('YES')
	else:
		print('NO')


import math
t = int(input())
Q = [tuple(map(int, input().split())) for i in range(t)]

def prime(a):
	for i in range(2, math.ceil(math.sqrt(a)) + 1):
		if a % i == 0:
			return 0
	else:
		return 1
for (i, j) in Q:
	if i - j == 1 and prime(i + j) == 1:
		print('YES')
	else:
		print('NO')


import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

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

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

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

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

def wr(arr):
	return ' '.join(map(str, arr))

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def revn(n):
	m = 0
	while n > 0:
		m = m * 10 + n % 10
		n = n // 10
	return m
t = ii()
for i in range(t):
	(a, b) = mi()
	print('YES') if a - b == 1 and prime(a + b) else print('NO')


def is_prime(n):
	d = 3
	while d ** 2 <= n:
		if n % d == 0:
			return False
		d += 2
	return True
t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	if a - b == 1:
		num = a + b
		if is_prime(num):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import math

def pr(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for divisor in range(3, sqr, 2):
		if n % divisor == 0:
			return False
	return True
n = int(input())
for i in range(n):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	if x - y == 1 and pr(x + y):
		print('YES')
	else:
		print('NO')


x = int(input())
for _ in range(x):
	a = [int(i) for i in input().split()]
	n = a[0] - a[1]
	if n != 1:
		print('NO')
	else:
		n = a[0] + a[1]
		l = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				l = False
				break
		if l:
			print('YES')
		else:
			print('NO')


t = int(input())

def isPrime(d):
	if d <= 1:
		return False
	if d <= 3:
		return True
	if d % 2 == 0 or d % 3 == 0:
		return False
	i = 5
	while i * i <= d:
		if d % i == 0 or d % (i + 2) == 0:
			return False
		i += 6
	return True
for i in range(t):
	(a, b) = list(map(int, input().split()))
	d = a - b
	s = a + b
	if d == 1 and isPrime(s):
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for j in range(t):
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
	else:
		ok = True
		bb = a + b
		for i in range(2, int((math.sqrt(bb) + 1) // 1)):
			if bb % i == 0:
				ok = False
				break
		if ok:
			print('YES')
		else:
			print('NO')


import math as m

def innput():
	return [int(i) for i in input().split()]

def prime(x):
	if x % 2 == 0 or x == 1:
		return False
	f = True
	lim = m.ceil(m.sqrt(x)) + 1
	i = 3
	while i < lim:
		if m.ceil(x / i) == m.floor(x / i):
			return False
		i += 2
	return True

def main():
	n = innput()[0]
	for i in range(n):
		(b, a) = innput()
		c = (b + a) * (b - a)
		if prime(c):
			print('YES')
		else:
			print('NO')
main()


def isPrime(n):
	global primes
	for p in primes:
		if n % p == 0:
			return False
		if p * p > n:
			return True
	return True
erath = [True] * 1000001
erath[0] = False
erath[1] = False
for p in range(2, 1000 + 1):
	if erath[p] == False:
		continue
	for m in range(p * p, 1000000 + 1, p):
		erath[m] = False
primes = [n for n in range(1000000) if erath[n] == True]
cases = int(input())
for i in range(cases):
	nums = [int(n) for n in input().split()]
	if nums[0] - nums[1] == 1 and isPrime(nums[0] + nums[1]):
		print('YES')
	else:
		print('NO')


import math

def is_prime(g):
	limit = math.sqrt(g)
	o = 2
	while o <= limit:
		if g % o == 0:
			return 'NO'
		o += 1
	return 'YES'
t = int(input())
ans = ['NO'] * t
for i in range(t):
	(a, b) = list(map(int, input().split()))
	v = is_prime(a + b)
	if a - b == 1 and v == 'YES':
		ans[i] = 'YES'
for i in range(t):
	print(ans[i])


nb_test = int(input())
for _ in range(nb_test):
	(a, b) = [int(x) for x in input().split()]
	if a - b != 1:
		print('NO')
	else:
		ans = 'YES'
		a += b
		i = 2
		while i * i <= a:
			if a % i == 0:
				ans = 'NO'
				break
			i += 1
		print(ans)


import math
T = int(input())

def is_prime(n):
	if n == 2 or n == 3:
		return True
	upper = int(math.sqrt(n)) + 1
	for i in range(2, upper + 1):
		if n % i == 0:
			return False
	return True
for i in range(T):
	(x, y) = list(map(int, input().split()))
	if x - y > 1:
		print('NO')
		continue
	z = x + y
	if is_prime(z):
		print('YES')
	else:
		print('NO')


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	sum = a + b
	diff = a - b
	ans = 0
	if diff != 1:
		ans = 0
	elif isPrime(sum):
		ans = 1
	else:
		ans = 0
	if ans == 1:
		print('YES')
	else:
		print('NO')
	t -= 1


t = int(input())
N = 1000000
import math
primes = [True] * (N + 1)
primes[0] = primes[1] = False
for i in range(2, N + 1):
	if primes[i]:
		for j in range(i * i, N + 1, i):
			primes[j] = False

def prime(v):
	if v < N:
		return primes[v]
	for i in range(2, N):
		if v % i == 0:
			return False
	return True

def ok(a, b):
	(a1, b1) = (a - b, a + b)
	if a1 == 1 and prime(b1):
		return True
	return False
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if ok(a, b):
		print('YES')
	else:
		print('NO')


import math

def pr(x):
	if x <= 1:
		return False
	p = int(math.sqrt(x)) + 1
	for i in range(2, p):
		if x % i == 0:
			return False
	return True
t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	if x != y + 1:
		print('NO')
	elif pr(x + y):
		print('YES')
	else:
		print('NO')


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a - b == 1:
		p = a + b
		s = math.floor(math.sqrt(p)) + 1
		c = 0
		for i in range(2, s):
			if p % i == 0:
				c += 1
		if c == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from math import sqrt

def ans(a, b):
	if a - b == 1:
		if a + b == 2:
			return 'YES'
		else:
			k = a + b
			for i in range(3, int(sqrt(k) + 1), 2):
				if k % i == 0:
					return 'NO'
			else:
				return 'YES'
	else:
		return 'NO'
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(ans(a, b))


from math import sqrt

def prim(a):
	for i in range(2, int(sqrt(a)) + 1):
		if a % i == 0:
			return True
	return False
for i in range(int(input())):
	(x, y) = map(int, input().split())
	if x - y == 1 and prim(x + y) == False:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	good = 1
	if abs(a - b) != 1:
		good = 0
	i = 2
	a += b
	while i * i <= a and good == 1:
		if a % i == 0:
			good = 0
		i += 1
	print(('NO', 'YES')[good])


t = int(input())

def prime(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a - b != 1:
		print('NO')
	elif prime(b + a) != True:
		print('NO')
	else:
		print('YES')


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().strip().split(' '))
	if n - k == 1:
		if (n + k) % 2 == 0:
			print('NO')
		else:
			f = 0
			j = 3
			while j <= math.ceil(math.sqrt(n + k)):
				if (n + k) % j == 0:
					print('NO')
					f = 1
					break
				j += 2
			if f == 0:
				print('YES')
	else:
		print('NO')


from math import sqrt
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	first = a - b
	second = a + b
	if first != 1:
		print('NO')
	else:
		f = False
		for i in range(2, int(sqrt(second)) + 1):
			if second % i == 0:
				f = True
				break
		if f:
			print('NO')
		else:
			print('YES')


import math

def list_primes_upto(upto: int):
	pcl = [True for x in range(upto + 1)]
	primes_list = []
	if upto >= 2:
		primes_list.append(2)
	if upto >= 3:
		primes_list.append(3)
	for i in range(6, upto + 2, 6):
		if i - 1 <= upto and pcl[i - 1]:
			primes_list.append(i - 1)
			for k in range((i - 1) ** 2, upto + 1, (i - 1) * 2):
				pcl[k] = False
		if i + 1 <= upto and pcl[i + 1]:
			primes_list.append(i + 1)
			for k in range((i + 1) ** 2, upto + 1, (i + 1) * 2):
				pcl[k] = False
	return primes_list
t = int(input())
tests = []
for q in range(t):
	tests.append([int(x) for x in input().split()])
check_limit = 0
for (a, b) in tests:
	if a - b == 1:
		check_limit = max(check_limit, a + b)
primes = list_primes_upto(int(math.sqrt(check_limit)) + 1)
for (a, b) in tests:
	yes = True
	if a - b != 1:
		yes = False
	if yes:
		apb = a + b
		is_apb_prime = True
		for p in primes:
			if not is_apb_prime or p >= apb:
				break
			is_apb_prime = is_apb_prime and apb % p != 0
		yes = yes and is_apb_prime
	print('YES' if yes else 'NO')


t = int(input())
R = lambda : map(int, input().split())
import math
ans = []
for _ in range(t):
	(a, b) = R()
	if a - b != 1:
		ans.append('NO')
	else:
		x = a + b
		isp = True
		for i in range(2, int(math.sqrt(x) + 2)):
			if i != x and x % i == 0:
				isp = False
				break
		ans.append('YES' if isp else 'NO')
print('\n'.join(ans))


n = int(input())
z = []

def p(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True
for i in range(n):
	a = list(map(int, input().split()))
	if a[0] - 1 == a[1] and p(a[0] + a[1]):
		z += ['YES']
	else:
		z += ['NO']
for i in z:
	print(i)


q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	if a > b + 1:
		print('NO')
	else:
		c = a + b
		d = 2
		f = 0
		while d ** 2 <= c:
			if c % d == 0:
				f = 1
			d += 1
		if f == 0:
			print('YES')
		else:
			print('NO')


a = int(input())

def isPrime2(n):
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n < 2:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
ques = []
for i in range(a):
	temp = input().split()
	temp = [int(j) for j in temp]
	ques += [temp]
for temp in ques:
	if temp[0] - temp[1] == 1 and isPrime2(temp[0] + temp[1]) == True:
		print('YES')
	else:
		print('NO')


n = int(input())
a = [0] * n
for i in range(n):
	a[i] = list(map(int, input().split()))
for i in range(n):
	if abs(a[i][0] - a[i][1]) == 1:
		st = [1] * (int((a[i][0] + a[i][1]) ** 0.5) + 1)
		for q in range(2, int((a[i][0] + a[i][1]) ** 0.5) + 1):
			st[q] = (a[i][0] + a[i][1]) % q
		if 0 in st:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


from math import *

def isPrime(a):
	if a < 2:
		return False
	else:
		for i in range(2, int(sqrt(a)) + 1):
			if a % i == 0:
				return False
		return True

def cal(a, b):
	if a - b == 1 and isPrime(a + b):
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	cal(a, b)


t = int(input())

def prime(n):
	if n == 1:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
while t > 0:
	a = list(map(int, input().split(' ')))
	if prime(a[0] + a[1]) and abs(a[0] - a[1]) == 1:
		print('YES')
	else:
		print('NO')
	t -= 1


def isPrime(n):
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n < 2:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = int(input())
if 1 <= n <= 5:
	scores = []
	for i in range(n):
		(a, b) = map(int, input().split())
		if a - b != 1:
			scores.append('NO')
			continue
		elif isPrime(a + b):
			scores.append('YES')
		else:
			scores.append('NO')
	for i in range(len(scores)):
		print(scores[i])


def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True
for i in range(int(input())):
	(a, b) = map(int, input().split())
	z = a + b
	x = a - b
	if x == 1:
		if isprime(z):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from sys import stdin
t = int(stdin.readline())
while t > 0:
	(a, b) = map(int, stdin.readline().split())
	if a - b > 1 or (a + b) % 2 == 0:
		print('NO')
		t -= 1
		continue
	i = 3
	flag = 0
	while i * i <= a + b:
		if (a + b) % i == 0:
			flag = 1
			break
		i += 2
	if flag == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


def prime(a):
	if a == 2:
		return False
	elif a % 2 == 0:
		return True
	else:
		for i in range(3, int(a ** 0.5) + 1, 2):
			if a % i == 0:
				return False
		return True
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if abs(a - b) == 1:
		if prime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


x = int(input())
for i in range(x):
	flag = 0
	(a, b) = map(int, input().split())
	if a - b > 1:
		print('NO')
	else:
		for i in range(2, int(pow(a + b, 1 / 2)) + 1):
			if (a + b) % i == 0:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			print('YES')


def check_prime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
m = 10 ** 8
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a - b == 1 and check_prime(a + b) == True:
		print('YES')
	else:
		print('NO')


def sieve(n):
	A = [1] * (n + 1)
	(A[0], A[1]) = (0, 0)
	for i in range(2, n + 1):
		if A[i] == 1:
			A[i * i::i] = [0 for _ in range(len(A[i * i::i]))]
	return A
n = 1000000
sieve_arr = sieve(n)
primes = [x for x in range(n + 1) if sieve_arr[x] == 1]

def is_prime(n):
	if n < 1000000:
		return sieve_arr[n] == 1
	for x in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]:
		if n % x == 0:
			return False
	(d, s) = (n - 1, 0)
	while d & 1 == 0:
		(d, s) = (d >> 1, s + 1)
	for a in (2, 3):
		if pow(a, d, n) == 1:
			continue
		is_composite = True
		for i in range(s):
			if pow(a, (1 << i) * d, n) == n - 1:
				is_composite = False
				break
		if is_composite:
			return False
	return True

def solve():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		print('YES' if is_prime(abs(int(pow(a, 2)) - int(pow(b, 2)))) else 'NO')
solve()


read = lambda : map(int, input().split())

def prime(x):
	d = 2
	while d * d <= x:
		if x % d == 0:
			return 0
		d += 1
	return 1
t = int(input())
res = ''
for i in range(t):
	(a, b) = read()
	res += 'YES\n' if a - b == 1 and prime(a + b) else 'NO\n'
print(res)


def isprime(num):
	sqrtnum = int(num ** 0.5)
	for i in list(range(2, sqrtnum + 1)):
		if num % i == 0:
			return False
	return True
t = int(input())
while t:
	tmp = input().split()
	x = int(tmp[0])
	y = int(tmp[1])
	a1 = x - y
	a2 = x + y
	if a1 != 1:
		print('NO')
	elif isprime(a2):
		print('YES')
	else:
		print('NO')
	t -= 1


def main():
	n = int(input())
	L = [None] * n
	for i in range(n):
		L[i] = (int(x) for x in input().split())
	solver(L)

def primeSieve(n):
	booleans = [True] * (n + 1)
	booleans[0] = False
	booleans[1] = False
	for x in range(2, int(n ** 0.5) + 1):
		if booleans[x] == True:
			for y in range(x ** 2, n + 1, x):
				booleans[y] = False
	return booleans

def isPrime(n):
	if n < 2:
		return False
	elif n % 2 == 0:
		return n == 2
	else:
		for x in range(3, int(n ** 0.5) + 1, 2):
			if n % x == 0:
				return False
	return True

def solver(L):
	for (a, b) in L:
		if a - b == 1 and isPrime(a + b):
			print('YES')
		else:
			print('NO')

def solver2(L):
	primes = primeSieve(10 ** 3)
	for (a, b) in L:
		if primes[a ** 2 - b ** 2]:
			print('YES')
		else:
			print('NO')
main()


def main():

	def isPrime(n):
		if n == 2 or n == 3:
			return True
		if n % 2 == 0 or n < 2:
			return False
		for i in range(3, int(n ** 0.5) + 1, 2):
			if n % i == 0:
				return False
		return True
	n = int(input())
	for _ in range(n):
		(hi, lo) = map(int, input().split())
		print('YES' if isPrime(hi + lo) and hi - lo == 1 else 'NO')
main()


t = int(input())
import math
while t:
	t -= 1
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
	else:
		f = 0
		for i in range(2, int(math.sqrt(a + b)) + 1):
			if (a + b) % i == 0:
				f = 1
				break
		if f:
			print('NO')
		else:
			print('YES')


def isPrime(n):
	for i in range(2, 1000001):
		if i == n:
			break
		if n % i == 0:
			return False
	return True
a = int(input())
for i in range(a):
	aaa = input().split()
	b = int(aaa[0])
	c = int(aaa[1])
	if b - c != 1:
		print('NO')
	elif isPrime(b + c):
		print('YES')
	else:
		print('NO')


def primefactor(num):
	a = []
	p = 2
	f = 1
	while p * p <= num:
		while num % p == 0:
			a.append(p)
			num = num // p
		p = p + 1
	if num > 1:
		a.append(num)
	return a

def prime(d):
	if primefactor(d) == [d]:
		print('YES')
	else:
		print('NO')
t = int(input())
for i in range(t):
	a = list(map(int, input().strip().split(' ')))[:2]
	d = a[0] - a[1]
	d1 = a[0] + a[1]
	if d != 1:
		print('NO')
	else:
		prime(d1)


def main():
	n = int(input())
	for _i in range(n):
		squares = input().split()
		squares[0] = int(squares[0])
		squares[1] = int(squares[1])
		prime_diff(squares[0], squares[1])

def prime_diff(sq1, sq2):
	if sq1 - sq2 == 1 and prime(sq1 + sq2):
		print('YES')
	else:
		print('NO')

def prime(num):
	i = 2
	while i * i <= num:
		if num % i == 0:
			return False
		i += 1
	return True
main()


from math import sqrt

def prem(a):
	for i in range(2, int(sqrt(a)) + 1):
		if a % i == 0:
			return False
	return True
t = int(input())
l = []
for i in range(t):
	s = input().split()
	l.append(s)
for i in range(t):
	if int(l[i][0]) - int(l[i][1]) != 1:
		print('NO')
	elif prem(int(l[i][0]) + int(l[i][1])):
		print('YES')
	else:
		print('NO')


from math import *

def checkPrime(n):
	if n <= 3:
		return n >= 2
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(sqrt(n)) + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n - m == 1 and checkPrime(n + m):
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b > 1:
		print('NO')
		continue
	x = 2
	flag = 0
	while x * x <= a + b:
		if (a + b) % x == 0:
			flag = 1
			break
		x += 1
	if flag:
		print('NO')
	else:
		print('YES')


import math
import queue
t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	if a >= b + 2:
		print('NO')
	else:
		n = 2 * b + 1
		prime = True
		for m in range(2, n):
			if m * m > n:
				break
			if n % m == 0:
				prime = False
				break
		if prime:
			print('YES')
		else:
			print('NO')


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = map(int, input().split())
	if n - m > 1:
		print('NO')
		continue
	x = n * n - m * m
	i = 2
	hna = 0
	while i * i <= x:
		if x % i == 0:
			hna = 1
			break
		i = i + 1
	if hna == 0:
		print('YES')
	else:
		print('NO')


def millerRabin(n):
	n = int(n)
	if n <= 1:
		return 0
	primes = [2, 3, 5, 7, 11, 13, 17, 37]
	for p in primes:
		if n == p:
			return 1
		if n % p == 0:
			return 0
	s = 0
	d = n - 1
	while d % 2 == 0:
		s += 1
		d //= 2
	for p in primes:
		x = pow(p, d, n)
		if x == 1 or x == n - 1:
			continue
		for i in range(s - 1):
			x = pow(x, 2, n)
			if x == n - 1:
				break
			if x == 1:
				return 0
		if not x * x % n == 1:
			return 0
	return 1
t = int(input())
for _ in range(t):
	[a, b] = list(map(int, input().rstrip().split()))
	print('YES' if millerRabin(a ** 2 - b ** 2) else 'NO')


from collections import deque
from sys import stdin
lines = deque((line.strip() for line in stdin.readlines()))

def nextline():
	return lines.popleft()

def types(cast, sep=None):
	return tuple((cast(x) for x in strs(sep=sep)))

def ints(sep=None):
	return types(int, sep=sep)

def strs(sep=None):
	return tuple(nextline()) if sep == '' else tuple(nextline().split(sep=sep))

def main():
	primes = [True] * 447224
	primes[0] = False
	primes[1] = False
	for i in range(2, len(primes)):
		if primes[i]:
			for j in range(2 * i, len(primes), i):
				primes[j] = False
	primes = list((i for (i, is_prime) in enumerate(primes) if is_prime))
	T = int(nextline())
	for testCase in range(1, T + 1):
		(a, b) = ints()
		if a - b != 1:
			print('NO')
			continue
		total = a + b
		is_prime = True
		for prime in primes:
			if total % prime == 0:
				is_prime = total == prime
				break
			elif prime > total:
				break
		print('YES' if is_prime else 'NO')
main()


import math

def prime(n):
	f = 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			f = 1
			break
		else:
			f = 0
	if f == 0:
		return 1
	else:
		return 0
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if abs(a - b) > 1:
		print('NO')
	elif prime(a + b) == 1:
		print('YES')
	else:
		print('NO')


def is_prime(num):
	for div in range(2, int(num ** 0.5) + 1):
		if num % div == 0:
			return False
	return True

def read_nums():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(a, b) = read_nums()
	if a - b != 1:
		print('NO')
	elif is_prime(a + b):
		print('YES')
	else:
		print('NO')


from math import sqrt
t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a - b == 1:
		c = int(a + b)
		for j in range(2, int(sqrt(c)) + 1):
			if c % j == 0:
				print('NO')
				break
		else:
			print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	(l, r) = map(int, input().split())
	a = l - r
	b = l + r
	d = 0
	j = 2
	while j * j <= b:
		if b % j == 0:
			d = 1
		j += 1
	if a == 1 and d == 0:
		print('YES')
	else:
		print('NO')


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')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

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

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():

	def isP(n):
		if n == 0 or n == 1:
			return False
		for i in range(2, n):
			if i * i > n:
				break
			if n % i == 0:
				return False
		return True
	for _ in range(N()):
		(a, b) = RL()
		print('YES' if a - b == 1 and isP(a + b) else 'NO')
main()


from math import sqrt
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a - b != 1:
		print('NO')
		continue
	for i in range(2, int(sqrt(a + b)) + 1):
		if (a + b) % i == 0:
			print('NO')
			break
	else:
		print('YES')


import random as r

def isprime(n):
	k = 5
	if n <= 1 or n == 4:
		return 0
	if n <= 3:
		return 1
	while k:
		a = 2 + r.randint(1, n - 4)
		if pow(a, n - 1, n) != 1:
			return 0
		k -= 1
	return 1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print('YES' if isprime(a * a - b * b) else 'NO')


is_prime = lambda x: all((x % d for d in range(2, int(x ** 0.5) + 1)))
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print('YES' if a == b + 1 and is_prime(a + b) else 'NO')


import math

def smallest(n):
	while n % 2 == 0:
		return 2
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			return i
			n = n / i
	if n > 2:
		return n
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b == 1:
		if smallest(a + b) == a + b:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import math
import os
import random
import re
import sys
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	c = a + b
	i = 2
	flag = 0
	if a - b == 1:
		for i in range(2, int(math.sqrt(c) + 1)):
			if c % i == 0:
				flag = 1
				break
			else:
				i += 1
	else:
		flag = 1
	if flag == 1:
		print('NO')
	else:
		print('YES')
	t -= 1


def miller_rabin_primality_test(n):

	def mr_check_one(n):
		m = n - 1
		n = n - 1
		k = 1
		while n % 2 ** k == 0:
			m = n // 2 ** k
			k = k + 1
		return m

	def mr_check_two(n, m, a=[2, 3]):
		for i in range(0, len(a)):
			a = a[i]
			b = pow(a, m, n)
			i = 0
			if b == n - 1 or b == 1:
				return True
			while b != n - 1 and i < 7:
				b = pow(b, 2, n)
				i = i + 1
			if b != n - 1:
				return False
			else:
				return True
	m = mr_check_one(n)
	r = mr_check_two(n, m)
	return r
t = int(input())
i = 0
a = []
while i < t:
	(x, y) = map(int, input().split())
	i += 1
	a.append(x)
	a.append(y)
i = 0
while i < 2 * t:
	if abs(a[i + 1] - a[i]) != 1:
		print('NO')
	elif miller_rabin_primality_test(a[i + 1] + a[i]) == True:
		print('YES')
	else:
		print('NO')
	i += 2


def check_final(a, b):
	re = a - b <= 1 and check_prime(a + b)
	if re:
		return 'YES'
	else:
		return 'NO'

def check_prime(x):
	if x < 2:
		return True
	elif x != 2 and x % 2 == 0:
		return False
	else:
		return all((x % i for i in range(3, int(x ** 0.5) + 1)))
q = int(input())
answer = []
for i in range(q):
	(a, b) = map(int, input().split())
	answer.append(check_final(a, b))
print(*answer)


import sys
input = sys.stdin.readline

def isPrime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	if n % 2 == 0:
		return False
	i = 3
	while i * i <= n:
		if n % i == 0:
			return False
		i += 2
	return True
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a - b == 1:
		if isPrime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
f = lambda : list(map(int, input().split()))
h = []
for i in range(t):
	h.append(f())
from math import sqrt

def premier(n):
	for i in range(2, int(sqrt(n) + 1)):
		if n % i == 0:
			return False
	return True
for i in range(t):
	if h[i][0] - h[i][1] == 1 and premier(h[i][0] + h[i][1]):
		print('YES')
	else:
		print('NO')


import math

def primenum(x):
	count = 0
	for i in range(2, int(math.floor(math.sqrt(x))) + 1):
		if x % i == 0:
			count = count + 1
	if count == 0:
		return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b == 1 and primenum(a + b) == True:
		print('YES')
	else:
		print('NO')


def is_prime(x):
	if x == 2 or x == 3:
		return True
	elif x < 2 or x % 2 == 0:
		return False
	else:
		for i in range(3, x, 2):
			if i * i > x:
				return True
			if x % i == 0:
				return False
T = int(input())
for i in range(T):
	(a, b) = [int(s) for s in input().split()]
	if a - b != 1:
		print('NO')
	elif is_prime(a + b):
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for i in range(0, t):
	(m, n) = map(int, input().split())
	diff = m - n
	if diff != 1:
		print('NO')
		continue
	s = m + n
	for j in range(2, int(math.sqrt(m + n)) + 1):
		if s % j == 0:
			print('NO')
			break
	else:
		print('YES')


t = int(input())
for _ in range(t):
	(A, B) = map(int, input().split())
	if A - B > 1:
		print('NO')
	else:
		A += B
		i = 2
		while i ** 2 <= A:
			if A % i == 0:
				print('NO')
				break
			i += 1
		else:
			print('YES')


def is_prime(n):
	return n > 1 and all((n % d for d in range(2, int(n ** 0.5) + 1)))

def solve(a, b):
	return is_prime(a ** 2 - b ** 2)
t = int(input())
for _ in range(t):
	(a, b) = (int(n) for n in input().split())
	if a - b == 1:
		if is_prime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


from functools import reduce
n = int(input())

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

def prime(data):
	a = data[0] - data[1]
	b = factors(data[0] + data[1])
	if a == 1 and b == True:
		return 'YES'
	else:
		return 'NO'
for i in range(n):
	print(prime([int(x) for x in input().split()]))


from random import randint

def miller_rabin_test(a, n):
	d = n - 1
	while d % 2 != 1:
		d //= 2
	pow_u = pow(a, d, n)
	if pow_u == 1:
		return True
	while d != n - 1 and n - 1 != pow_u:
		d *= 2
		pow_u *= pow_u
		pow_u %= n
	if pow_u == n - 1 and d != n - 1:
		return True
	return False

def miller_rabin_primality_test(n, m):
	for q in range(m):
		if not miller_rabin_test(randint(2, n - 1), n):
			return False
	return True
n = int(input())
for q in range(n):
	(a, b) = map(int, input().split())
	if miller_rabin_primality_test(a * a - b * b, 17):
		print('YES')
	else:
		print('NO')


import sys
f = sys.stdin
out = sys.stdout

def is_prime(n):
	if n == 2 or n == 3:
		return True
	if n < 2 or n % 2 == 0:
		return False
	if n < 9:
		return True
	if n % 3 == 0:
		return False
	r = int(n ** 0.5)
	f = 5
	while f <= r:
		if n % f == 0:
			return False
		if n % (f + 2) == 0:
			return False
		f += 6
	return True
t = int(f.readline().rstrip('\r\n'))
for i in range(t):
	(b, a) = map(int, f.readline().rstrip('\r\n').split())
	if abs(b - a) == 1:
		area = a + b
		if is_prime(area):
			out.write('YES\n')
		else:
			out.write('NO\n')
	else:
		out.write('NO\n')


N = 1000000

def rwh_primes_x(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [i for i in range(3, n, 2) if sieve[i]]
primes = rwh_primes_x(N)

def isPrime(x):
	if x < N:
		return x in primes
	else:
		for p in primes:
			if x % p == 0:
				return False
			elif p * p > x:
				return True
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	if a - b > 1:
		print('NO')
	elif isPrime(a + b):
		print('YES')
	else:
		print('NO')


def is_prime(n):
	if n == 1:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	flag = 0
	if a - b == 1:
		if is_prime(a + b):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


def is_prime(n):
	i = 2
	while i * i <= n:
		if n == 1:
			return 0
		if n == 2 or n == 3:
			return 1
		if n % i == 0:
			return 0
		else:
			i += 1
	return 1
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a - b == 1:
		if is_prime(a + b) == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split(' '))
		if a - b == 1:
			temp = a + b
			chk = 0
			for x in range(2, math.floor(math.sqrt(temp)) + 2):
				if temp % x == 0:
					chk = 1
					break
			if chk == 1:
				print('NO')
			else:
				print('YES')
		else:
			print('NO')
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 math

class CodeforcesTask1033BSolution:

	def __init__(self):
		self.result = ''
		self.t = 0
		self.tests = []

	def read_input(self):
		self.t = int(input())
		for x in range(self.t):
			self.tests.append([int(y) for y in input().split(' ')])

	def process_task(self):
		results = []
		for test in self.tests:
			c = test[0] - test[1]
			if c == 1:
				is_prime = True
				d = sum(test)
				for x in range(2, int(math.sqrt(d)) + 1):
					if not d % x:
						is_prime = False
						break
			else:
				is_prime = False
			results.append('YES' if is_prime else 'NO')
		self.result = '\n'.join(results)

	def get_result(self):
		return self.result
Solution = CodeforcesTask1033BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


from math import *

def isprim(a):
	for i in range(2, int(sqrt(a)) + 1):
		if a % i == 0:
			return False
	return True
T = int(input())
while T:
	T -= 1
	(b, a) = map(int, input().split())
	if b - a == 1 and isprim(b + a):
		print('YES')
	else:
		print('NO')


import math

def f(l):
	(a, b) = l
	if a - b > 1:
		return False
	s = a + b
	r = int(math.sqrt(s))
	for i in range(3, r + 2):
		if s % i == 0:
			return False
	return True
q = int(input())
for _ in range(q):
	l = list(map(int, input().split()))
	print('YES' if f(l) else 'NO')


def is_prime(a):
	return a > 1 and all((a % i for i in range(2, int(a ** 0.5) + 1)))
t = int(input())
ans = []
for _ in range(t):
	(a, b) = map(int, input().split())
	if a - b > 1:
		ans.append('NO')
	elif is_prime(a + b) == False:
		ans.append('NO')
	else:
		ans.append('YES')
print(*ans)


import math

def isprime(x):
	a = 0
	for i in range(3, int(math.sqrt(x) + 1), 2):
		if x % i == 0:
			a = 1
			break
	if a == 0:
		return 'YES'
	else:
		return 'NO'
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a - b == 1:
		print(isprime(a + b))
	else:
		print('NO')


import math
ntc = int(input())

def is_prime(x):
	if x <= 1:
		return False
	if x == 2:
		return True
	if x % 2 == 0:
		return False
	bound = int(math.sqrt(x))
	for i in range(3, bound + 1, 2):
		if x % i == 0:
			return False
	return True

def is_yes(a, b):
	if abs(a - b) != 1:
		return False
	x = a + b
	return is_prime(x)
for tc in range(ntc):
	(a, b) = map(int, input().split())
	print('YES' if is_yes(a, b) else 'NO')


from math import ceil
t = int(input())

def isprime(x):
	for i in range(2, ceil(x ** 0.5) + 1):
		if x % i == 0:
			return False
	return True
for i in range(t):
	(x, y) = map(int, input().split())
	if x - y != 1:
		print('NO')
		continue
	elif isprime(x + y):
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n - m > 1:
		print('NO')
	else:
		x = 2
		while x * x <= n + m:
			if 0 == (n + m) % x:
				print('NO')
				break
			x += 1
		else:
			print('YES')


from math import sqrt

def prime(z):
	for i in range(2, int(sqrt(z)) + 1):
		if z % i == 0:
			return 0
	return 1
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n - k == 1 and prime(n + k):
		print('YES')
	else:
		print('NO')


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if abs(a - b) != 1:
		print('NO')
		continue
	check = a + b
	is_prime = True
	if check % 2 == 0:
		is_prime = False
	else:
		for i in range(3, int(math.sqrt(check)) + 1, 2):
			if check % i == 0:
				is_prime = False
				break
	print('YES' if is_prime else 'NO')