def prime(num):
	flag=0
	if num ==1:
		return 0
	for i in range(2,(num/2)+1):
		if num%i==0:
			flag=1
			break
	if flag==1:
		return 0
	else:
		return 1
def sumdig(num):
	res=0
	while(num>0):
		res += (num%10)
		num/=10
	return res
for _ in range(int(raw_input())):
	n = int(raw_input())
	s = sumdig(n)
	res = prime(s)
	if res==1:
		print "YES"
	else:
		print "NO"