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
# your code goes here
import math
def prime(n):
	if(n<=1):
		return 0
	elif(n==2):
		return 1
	elif(not n&1):
		return 0
	else:
		for i in range(3,int(math.sqrt(n))+1, 2):
			if(n%i==0):
				return 0
	return 1	
	

t=int(input())
while t:
	t=t-1
	n=int(input())
	temp=n
	sum=0
	while(n) :
		r=n%10
		n=n/10
		sum+= r
	
	if(prime(temp) and prime(sum) ):
		print 'YES'
	else:
		print 'NO'