import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
String lineNumStr = scanner.nextLine();
int lineNum = Integer.parseInt(lineNumStr);
//String[] lines = new String[lineNum];
for(int i = 0; i < lineNum; i ++)
{
//lines[i] = scanner.nextLine();
String str = scanner.nextLine();
int[] charNum = new int[26];
for(int j = 0; j < str.length(); j ++)
{
char ch = str.charAt(j);
charNum[ch - 'a'] ++;
}
Arrays.sort(charNum);
int beautifulVal = 0;
int startVal = 26;
for(int k = charNum.length - 1; k >= 0; k --)
{
if(charNum[k] != 0)
{
beautifulVal = beautifulVal + startVal * charNum[k];
startVal--;
}else{
break;
}
}
System.out.println(beautifulVal);
}
}
}
}