from collections import Counter
def isPrime(n):
    if(n<2):
        return 0
    if(n==2):
        return 1
    if(n&1==0):
        return 0
    for i in xrange(3,int(n**0.5)+1,2):
        if(n%i==0):
            return 0
    return 1

t=input()
while t:
    t=t-1
    a=raw_input()
    z=0
    j=sum(Counter(set(a)).values())    
    if(isPrime(j)):
        z=1
        for i in Counter(a).values():
            if(isPrime(i)==0):
                z=0
                break
    if(z==0):
        print 'NO'
    else:
        print 'YES'