def prime1(no):
  cnt2 = 0
  if no == 1:
  	return False
  for i in range(2,no):
    if no % i == 0:
	  cnt2 = 1
  if no == 2 or cnt2 == 0:
    return True
  else:
    return False
    
tc=input()
if tc>=1 and tc<=10:
    for j in range(0, tc):
      ret_val = 0
      M = raw_input()
      if len(M)>=1 and len(M)<=100000:
        b = set(M)
        flag = 1
        if not prime1(len(b)):
        	flag = 0
        else:	
          for i in set(b):
        	if not prime1(M.count(str(i))):
        	  flag = 0
        if flag == 1:
        	print "YES"
        else:
        	print "NO"