import sys
w = int(input())


n = [i.strip() for i in sys.stdin.readlines()]
#函数为取出不重复元素的次数,并按照降序排列
def func1(i):
    a = {}
    for j in list(set(i)):
        a[j] = i.count(j)
    w = sorted(a.values(), key=lambda x: x, reverse=True)
    return w
 
#循环输入的词组,并求值计算,因出现次数按照降序排列,所以漂亮值依次递减      
for i in n:
    kw = 26
    b = 0
    for j in func1(i):
        b = b + j*kw
        kw -= 1
    print(b)