while True:
    try:
        n = int(input())
        num=[i for i in range(26,0,-1)]
        for i in range(n):
            lst=input()
            dic={}
            result =0
            for w in lst:
                if w in dic:
                    dic[w]+=1
                else:
                    dic[w]=1
            t=0
            dic_new = sorted(dic.values(),reverse=True)
            for item in dic_new:
                result += item*num[t]
                t+=1
            print(result)
    except:
        break