'''
# 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
#print 'Hello World!'
def isprime(x) :
	if x < 2 :
		return False
	elif x == 2 :
		return True
	elif x%2 == 0 :
		return False
	else :
		for i in xrange(3,int(x**0.5)+1,2) :
			if x%i == 0 :
				return False
		return True
ans = "YES"
for i in range(int(raw_input())) :
	ans = "YES"
	x = Counter(raw_input())
	if not isprime(len(x)) :
		ans = "NO"
	else :
		for j in x:
			if not isprime(x[j]) :
				ans = "NO"
				break
	print ans