#include <string>
#include <iostream>
#include <cstring>

using namespace std;
int nums[126];
int main()
{
    int n1;
    while(cin>>n1)
    {
        while (n1-->0)
        {
            memset(nums,0,sizeof(int)*126);
            string a1;
            cin>>a1;
            for(char c1:a1)
            {
                ++nums[c1];
            }
            int w1=26,maxv=-1,ans=0,maxi;
            while(maxv!=0)
            {   maxv=0,maxi=0;
                for(int i=0;i<126;++i)
                {
                    if(nums[i]>maxv)
                    {
                        maxv=nums[i];
                        maxi=i;
                    }
                }
                nums[maxi]=0;
                ans+=maxv*(w1--);
                //cout<<maxv*(w1--)<<endl;
            }
            cout<<ans<<endl;

        }
        
        
    }
}