import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
for(int i = 0; i<n; i++){
String s = in.next();
//统计各字符出现的次数
Map<Character,Integer> hm = new HashMap<>();
for(int j = 0; j<s.length(); j++){
if(!hm.containsKey(s.charAt(j))){
hm.put(s.charAt(j),1);
}else{
hm.put(s.charAt(j),hm.get(s.charAt(j))+1);
}
}
List<Integer> al = new ArrayList<>();
//将哈希表中的值放如List中
for(Map.Entry<Character,Integer> e : hm.entrySet()){
al.add(e.getValue());
}
//外部比较器实现Integer类型的比较
al.sort(new Comparator<Integer>(){
public int compare(Integer i1, Integer i2) {
return i1.intValue() - i2.intValue();
}
});
int num = 26;
int sum = 0;
//倒序遍历将满意度累加
for(int k = al.size()-1; k>=0; k--){
sum += al.get(k) * num;
num--;
}
System.out.println(sum);
}
}
}
}