import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) {
            int n = Integer.parseInt(in.nextLine());
            List<String> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(in.nextLine());
            }
            for (String str : list) {
                String lowerCase = str.toLowerCase(Locale.ROOT);
                Map<Character, Integer> map = new LinkedHashMap<>();
                // 字符串分解,统计每个字符的个数
                for (char c : lowerCase.toCharArray()) {
                    map.put(c, map.getOrDefault(c, 0) + 1);
                }
                ArrayList<Map.Entry<Character, Integer>> entries = new ArrayList<>(map.entrySet());
                // 按字母个数从大到小排列
                entries.sort(new MyComparator());
                int sum = 0;
                for (int i = 0, j = 26; i < entries.size() && j > 0; i++, j--) {
                    Map.Entry<Character, Integer> entry = entries.get(i);
                    sum += entry.getValue() * j;
                }
                System.out.println(sum);
            }
        }
    }

    private static class MyComparator implements Comparator<Map.Entry<Character, Integer>> {

        @Override
        public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
            return o2.getValue() - o1.getValue();
        }
    }
}