package main
import (
"fmt"
"sort"
)
func main() {
var n int
_, _ = fmt.Scan(&n)
for i := 0; i < n; i++ {
input := ""
_, _ = fmt.Scan(&input)
countMap := map[byte]int{}
for _, c := range []byte(input) {
if _, ok := countMap[c]; !ok {
countMap[c] = 0
}
countMap[c]++
}
// fmt.Printf("countMap: %#v\n", countMap)
countSlice := []int{}
for _, v := range countMap {
countSlice = append(countSlice, v)
}
sort.Slice(countSlice, func(i2, j int) bool {
return countSlice[i2] > countSlice[j]
})
// fmt.Printf("countSlice2: %#v\n", countSlice)
r := 0
for idx, c := range countSlice {
r += (26 - idx) * c
}
fmt.Printf("%v\n", r)
}
}