'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def isprime(n):
    if(n==1):
    	return False
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False

    return True
t=input()
while(t):
	t-=1
	n=input()
	s=0
	while(n):
		s+=n%10
		n=n/10
	if(isprime(s)):
		print "YES"
	else :
		print "NO"