while True:
    try:
        m = int(input())
        for s in range(m):
            name = input()
            result = 0
            lists = list(set(name))
            list1 = sorted(lists, key=lambda x: name.count(x), reverse=True)
            time = 26
            for i in range(len(lists)):
                result += name.count(list1[i]) * time
                time -= 1
            print(result)
    except:
        break