#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int T;
cin >> T;
string str;
while(cin >> str) {
vector<int> alpha(26, 0);
for(const char& c: str) {
++alpha[c - 'a'];
}
sort(alpha.begin(), alpha.end(), greater<int>());
int beauty = 0, initial = 26;
for(const int& a: alpha) {
if(a) {
beauty += a * (initial--);
}
}
cout << beauty << endl;
}
return 0;
}



京公网安备 11010502036488号