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!'
from math import sqrt
def isprime(n):
	for i in range(2,int(sqrt(n))+1):
		if n%i==0:
			return 0
	return 1
t=input()
while t>0:
	t-=1
	n=input()
	s=str(n)
	p=0
	for i in s:
		p+=int(i)
	if isprime(n)==1 and isprime(p)==1:
		print"YES"
	else:
		print"NO"