import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextLine()) { // 注意 while 处理多个 case
int n = Integer.parseInt(in.nextLine());
for (int i = 0; i < n; i++) {
String str = in.nextLine();
System.out.println(getLatestLevel(str));
}
}
}
public static int getLatestLevel(String str) {
String strLower = str.toLowerCase();
int[] cache = new int[26];
for (int i = 0; i < strLower.length(); i++) {
cache[strLower.charAt(i)-'a']++;
}
Arrays.sort(cache);
int sum = 0;
int level = 26;
for (int i = cache.length - 1; i >= 0; i--) {
if (cache[i] == 0) {
break;
}
sum += cache[i] * level--;
}
return sum;
}
}