a number can be said dual prime. if the number is prime and the sum of digits of the number is also a prime number.
If a number is dual prime then print YES else print NO

SAMPLE INPUT
2
13
11

SAMPLE OUTPUT
NO
YES
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
def isPrime(n):
	if n == 0 or n == 1:
		return 0
	for i in range(2, n):
		if n % i == 0:
			return 0
	return 1
 
t = int(raw_input())
for cases in range(t):
	n = int(raw_input())
	if isPrime(n) == 1:
		sumDig = 0
		while n != 0:
			sumDig += n % 10
			n /= 10
		if isPrime(sumDig) == 1:
			print 'YES'
		else:
			print 'NO'
	else:
		print 'NO'