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
'''
def isprime(x):
	if x==1:
		return 0
	for i in range(2,x):
		if x%i==0:
			return 0
	return 1
t=input()
for _ in range(0,t):
	n=input()
	s=0
	c=n
	while(c):
		s+=c%10
		c/=10
	if(isprime(n)==0 or isprime(s)==0):
		print "NO"
	if(isprime(s)==1 and isprime(n)==1):
		print "YES"