带变量的排序。

最后都多余带key值,字符串解析完了后,直接把counter倒序排序乘过去就行了。

t = int(input().strip())

for _ in range(t):
    name = input().strip()
    alphabet = {}
    for each in name:
        if each not in alphabet:
            alphabet[each] = 1
        else:
            alphabet[each] += 1
    result = sorted(alphabet, key=lambda x: alphabet[x], reverse=True)
    curr_value = 26
    total_value = 0
    for each in result:
        total_value += curr_value * alphabet[each]
        curr_value -= 1
    print(total_value)