while True:
    try:
        n = int(input())
        names = []
        for i in range(n):
            names.append(input().lower())
        
        for name in names:
            zimu = {x:name.count(x) for x in name}
            zimu = sorted(zimu.items(), key = lambda kv:(kv[1], kv[0]),
                      reverse=True)
            s = 27
            z = 0
            for (_,i) in zimu:
                s -= 1
                z += s * i
            print(z)
            
    except:
        break