import java.util.Scanner;
public class Main {
private static int score(String str) {
str = str.toLowerCase();
int[] arr = new int[26];
for(int i=0; i<str.length(); i++) {
arr[(int)str.charAt(i) - 97]++;
}
int num = 0;
for(int i=0; i<26; i++)
num += arr[i];
int max = 0;
int flag = -1;
int ans = 0;
int cnt = 26;
for(int j=0; j<num; j++) {
for(int i=0; i<26; i++) {
if(arr[i] > max) {
max = arr[i];
flag = i;
}
}
ans += max * (cnt--);
arr[flag] = 0;
max = 0;
}
return ans;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
scan.nextLine();
while(scan.hasNextLine()) {
String name = scan.nextLine();
System.out.println(score(name));
}
}
}