#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int getBeauty(string& name) {
vector<int> count(26, 0); // 统计26个字母出现次数
// 统计每个字母出现的次数
for(char c : name) {
count[tolower(c) - 'a']++;
}
// 将出现次数从大到小排序
sort(count.begin(), count.end(), greater<int>());
// 计算漂亮度
int beauty = 0;
int value = 26; // 最大漂亮度从26开始
for(int i = 0; i < 26 && count[i] > 0; i++) {
beauty += count[i] * value--;
}
return beauty;
}
int main() {
int n;
cin >> n;
while(n--) {
string name;
cin >> name;
cout << getBeauty(name) << endl;
}
return 0;
}
import java.util.*;
public class Main {
public static int getBeauty(String name) {
int[] count = new int[26];
// 统计每个字母出现的次数
for(char c : name.toLowerCase().toCharArray()) {
count[c - 'a']++;
}
// 将出现次数从大到小排序
Arrays.sort(count);
// 计算漂亮度
int beauty = 0;
int value = 26;
for(int i = 25; i >= 0 && count[i] > 0; i--) {
beauty += count[i] * value--;
}
return beauty;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-- > 0) {
String name = sc.next();
System.out.println(getBeauty(name));
}
}
}
def get_beauty(name):
# 统计每个字母出现的次数
count = {}
for c in name.lower():
count[c] = count.get(c, 0) + 1
# 将出现次数从大到小排序
freq = sorted(count.values(), reverse=True)
# 计算漂亮度
beauty = 0
value = 26
for f in freq:
beauty += f * value
value -= 1
return beauty
n = int(input())
for _ in range(n):
name = input().strip()
print(get_beauty(name))