prime=[1]*(100000+1)
i=2
n=100000
prime1=[]
while i*i<=n:
    if prime[i]==1:
        j=i*2
        while j<=n:
            if prime[j]==1:
                prime[j]=0
            j+=i
    i=i+1
mod=pow(10,9)+7
for i in range(2,n+1):
    if prime[i]==1:
        prime1.append(i)
t=input()
while t>0:
	t=t-1
	a=raw_input()
	a=list(a)
	a.sort()
	b=set(a)
	f=0
	if len(b) in prime1:
		i=0
		while i<len(a):
			if a.count(a[i]) in prime1:
				i=i+a.count(a[i])
				continue
			else:
				f=1
				print 'NO'
				break
	else:
		f=1
		print 'NO'
	if f==0:
		print 'YES'