/*
* 时间: 2021-05-26 23:22
* 分析: 数组记录及排序
*/
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()) {
int nameCnt = sc.nextInt();
sc.nextLine();
for (int i = 0; i < nameCnt; i++) {
Integer words[] = new Integer[26];
for (int j = 0; j < 26; j++) {
words[j] = 0;
}
char name[] = sc.nextLine().toCharArray();
for (int j = 0; j < name.length; j++) {
int idx = Character.toLowerCase(name[j]) - 'a';
words[idx] += 1;
}
Arrays.sort(words, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return o2 - o1;
}
});
int result = 0;
for (int j = 0; j < 26; j++) {
if (words[j] == 0) {
break;
}
result += (26 - j) * words[j];
}
System.out.println(result);
}
}
}
}