t=input()
for i in xrange(t):
    n=raw_input()
    s=0
    for j in n:
        k=int(j)
        s=s+k
    if s!=1:
        for l in xrange(2,s):
            if s%l==0:
                print "NO"
                break
        else:
            print "YES"
    else:
        print "NO"