def func(lt):
    if lt < 2: return []
    if lt < 3: return [2]
    lmtbf = (lt - 3) // 2
    buf = [True] * (lmtbf + 1)
    for i in range((int(lt ** 0.5) - 3) // 2 + 1):
        if buf[i]:
            p = i + i + 3
            s = p * (i + 1) + i
            buf[s::p] = [False] * ((lmtbf - s) // p + 1)
    return [2] + [i + i + 3 for i, v in enumerate(buf) if v]
    
prime = func(100000)
T = input()
 
while T:
    S = raw_input()
    set_S = set(S)
    count = [0]
    if len(set_S) in prime:
        for i, x in enumerate(set_S, start = 1):
            if S.count(x) in prime:
                count[0] += 1
        if count[0] is len(set_S):
			print 'YES'
        else:
            print 'NO'
    else:
        print 'NO'
    T = T - 1