import math
def getSum(n):
	ans=0
	while n>0:
		ans+=n%10
		n=n/10
	return ans
	
	
def chkPrime(n):
	
    if n % 2 == 0 and n > 2: 
        return False
    if n <2:
    	return False
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True
    
t= input()
for _ in range(t):
	n=input()
	if chkPrime(getSum(n)):
		print "YES"
	else:
		print "NO"