name_list = []
while True:
try:
name_list.append(input())
except:
break
for i in name_list[1:]:
pld = 0
zm_list = []
for e in set(list(i)):
zm_list.append(i.count(e))
zm_list.sort(reverse=True)
n = 26
for j in zm_list:
pld += j * n
n -= 1
# print(zm_list)
# for j, e in range(26-len(set(i))+1, 26+1), set(i):
# pld += j * zm_dic[e]
print(pld)