def isPrime(n):
    if n < 2: 
         return False;
    if n % 2 == 0:
         return n == 2
    k = 3
    while k*k <= n:
         if n % k == 0:
             return False
         k += 2
    return True
for _ in range(int(raw_input())):
	if isPrime(sum(map(int, raw_input()))):
		print "YES"
	else:
		print "NO"