dp=[1]*101
def main():
	dp[0]=0
	dp[1]=0
	for i in range(2,10):
		if(dp[i]==1):
			j=i*i
			while(j<=100):
				dp[j]=0
				j=j+i
def sum(n):
	ans=0
	while(n>0):
		ans+=n%10
		n=n/10
	return ans
main()
t=int(raw_input())
while(t>0):
	n=int(raw_input())
	x=sum(n)
	if(dp[x]==1):
		print "YES"
	else:
		print "NO"
	t=t-1