def pseive(n):
    sieve = [True] * (int)(n/2)
    for i in range(3,int(n**0.5)+1,2):
        if sieve[(int)(i/2)]:
            sieve[(int)(i*i/2)::i] = [False] * (int)((n-i*i-1)/(2*i)+1)
    return [2] + [2*i+1 for i in range(1,(int)(n/2)) if sieve[i]]

def getSum(n):
	ans=0
	while n>0:
		ans+=n%10
		n=n/10
	return ans
    
t= input()
primes = pseive(10000)
for _ in range(t):
	n=input()
	if getSum(n) in primes:
		print "YES"
	else:
		print "NO"