def digsum(n):
    s=0
    while n>0:
        s=s+n%10
        n=int(n/10)
    return s
tc=int(input())
primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
while tc>0:
    s=int(input())
    if digsum(s) in primes:
        print 'YES'
    else:
        print 'NO'
    tc=tc-1