import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int n = sc.nextInt();
sc.nextLine();
for(int i = 0; i < n; ++i){
char[] cc = sc.nextLine().toCharArray();
fun(cc);
}
}
}
public static void fun(char[] cc){
HashMap<Character, Integer> map = new HashMap<>();
for(char c : cc){
map.put(c, map.getOrDefault(c,0) + 1);
}
int res = 0;
int[] num = new int[map.keySet().size()];
int index = 0;
for(Character c : map.keySet()){
num[index] = map.get(c);
index++;
}
Arrays.sort(num);
int mul = 26;
for(int i = num.length - 1; i >= 0; --i){
res += num[i] * mul;
mul--;
}
System.out.println(res);
}
}