import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();

        HashMap<Character, Integer> map = new HashMap<>();
        PriorityQueue<HashMap.Entry> pq = new PriorityQueue<>(
            (o1, o2)
        -> {
            return (int)o2.getValue() - (int)o1.getValue();
        });

        for (int t = 0; t < T; t++) {
            String str = in.next();
            //System.out.println(str);
            map.clear();
            pq.clear();
            for (int i = 0; i < str.length(); i++) {
                char c = str.charAt(i);
                map.put(c, map.getOrDefault(c, 0) + 1);
            }
            for (HashMap.Entry et : map.entrySet()) pq.add(et);

            long res = 0;
            int curScore = 26;
            while (!pq.isEmpty()) {
                int times = (int)pq.poll().getValue();
                res += times * curScore;
                curScore--;
            }
            System.out.println(res);
        }
    }
}