def getres(s):
	dic = {}
	temp = 0
	for mem in s:
		if mem in dic:
			dic[mem] = dic[mem]+1
		else:
			dic[mem] = 1
	#print dic
	ld = len(dic)
	#print ld
	if isprime(ld) == 1:
		for mem1 in dic:
			if isprime(dic[mem1]) == 1:
				pass
			else:
				temp = 1
				break
		if temp == 1:
			print "NO"
		else:
			print "YES"
	else:
		print "NO"

def isprime(a):
	if a ==1 :
		return 0
	if a == 2:
		return 1
	else:
		for mem in range(2,int(a**0.5)+1):
			#print mem
			if a% mem == 0:
				return 0
			else:
				pass
		else:
			return 1




t = int(raw_input())
for mem in range(t):
	s = str(raw_input())
	getres(s)
#	n = int(raw_input())
#	print isprime(n)