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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
from math import sqrt
def prime(n):
	if n==1:
		return 0
	for i in range(2,int(sqrt(n))+1):
		if n%i==0:
			return 0
	return 1
t=input()
while t>0:
	t-=1
	s=raw_input()
	c=0
	for i in s:
		c+=int(i)
	if prime(c)==1:
		print"YES"
	else:
		print"NO"