while(n = readline()){
    for(let i = 0; i < n; i++){
        let str = readline()
        let map = new Array(26).fill(0);
        let res = 0;
        let arr = str.toLowerCase().split('');
        arr.forEach((ele)=>{
            map[ele.charCodeAt(0)-97]++;
        })
        map.sort((a,b)=>b-a);
        for(let i=0;i<26;i++){
            res += map[i] * (26 - i)
        }
        console.log(res);
    }
}