'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
from collections import Counter
import string
from math import sqrt

def check_prime(n):
    if n<2:
        return False
    if n%2==0:
        return n==2
    if n%3==0:
        return n==3
    if n%5==0:
        return n==5
    for i in range(7, int(sqrt(n))+1, 2):
        if n%i == 0:
            return False
    return True

def count_letters(word):
	i=0
   	count=0
   	flag=0
   	j=len(word)
   	while(i<j):
   		b=word.count(word[i])
        	i=i+b
		count=count+1;
		tmp=check_prime(b)
      		if(tmp==False) :
			flag=1
			break
   	k=check_prime(count)
   	if(k==False) :
		flag=1  
   	if(flag==1) :
		print 'NO'
   	if(flag==0) :
		print 'YES'
t=input()
d=0
if t>10 :
	print "Error in giving number of test cases should be between 1 and 10"
elif t<1:
	print "Error in giving number of test cases should be between 1 and 10"
else :
    	while(d<t):       
		word = raw_input();
        	if(len(word)<1):
			print "Error in giving length of string,should be between 1 and 10^5"
			break
		elif(len(word)>100000):
			print "Error in giving length of string,should be between 1 and 10^5"
			break
		b=sorted(word)
		count_letters(b)
  		d=d+1