def is_prime(n):
	if n==1:
		return False
	if n==2 or n==3:
		return True
	if n%2==0:
		return False
	for i in xrange(2,n-1):
		if n%i==0:
			return False
	return True
			

def is_prime_string(s):
	letters = set(s)
	if not is_prime(len(letters)):
		return False
	for letter in letters:
		if not is_prime(s.count(letter)):
			return False
	return True

def main():
	n = int(raw_input())
	output = []
	while n>0:
		s = raw_input()
		output.append(is_prime_string(s))
		n-=1
	for o in output:
		print "YES" if o else "NO"
		

if __name__=='__main__':
	main()