#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define Maxsize 10005
int myCompare(const void *item1, const void *item2){
int *a = (int *)item1, *b = (int *)item2;
return *b - *a;
}
int main()
{
int i, j, n;
scanf("%d", &n);
for(i = 0; i < n; i++){
char str[Maxsize];
scanf("%s", str);
int array[26], len = strlen(str);
memset(array, 0, sizeof(int) * 26);
for(j = 0; j < len; j++){
if(str[j] >= 'a' && str[j] <= 'z'){
array[str[j] - 'a']++;
}
else if(str[j] >= 'A' && str[j] <= 'Z'){
array[str[j] - 'A']++;
}
}
qsort(array, 26, sizeof(int), myCompare);
int beauty = 0;
for(j = 0; j < 26; j++){
if(array[j]){
beauty += array[j] * (26 - j);
}
}
printf("%d\n", beauty);
}
return 0;
}