//逻辑比较烂,就是自己实现的字母统计完了(reduce比较好用一下就出来了),排序用26递减去乘
let arr = [];
while(line = readline()) {
arr.push(line);
}
const length = parseInt(arr[0]);
const newArr = arr.slice(1, length+1);
for(let item of newArr) {
let arr = item.split('').map(
x => x.toUpperCase()
);
let uniArr = Array.from(new Set(arr));
print(maxScore(arr, uniArr));
}
function maxScore(ini, uni) {
let arr = [];
let count = 0;
for (char of uni) {
let items = ini.filter(x => x == char);
arr.push(items.length);
}
arr.sort((a,b) => b - a);
for (let key in arr) {
count += arr[key] * (26 - key)
}
return count;
}