def primes(n): # sieve of eratosthenes
    ps, sieve = [2], [True] * (n + 1)
    for p in range(3, n + 1,2):
        if sieve[p]:
           ps.append(p)
           for i in range(p * p, n + 1, p):
               sieve[i] = False
    return ps
def strprime(a):
    k=0
    for i in set(a):
        p= a.count(i)
        if p not in s:
            k=1
            break
        else:
            continue
    return k
for _ in range(input()):
    a= raw_input()

    s= list(primes(len(a)))
    r= len(set(a))
    if r not in s:
        print "NO"
    elif strprime(a):
        print "NO"
    else:
        print "YES"