Now that we have recovered all our data, we can return to hacking in to the hacker's system. Our sources tell us that this hacker's lust for power is so great that it is reflected in everything he does, everything he creates. Perhaps this knowledge can become his weakness in our hands, his thirst for power laying a trap for him. News also arrives of a great weapon being developed by him, soon to be unleashed upon us. Can you break through the next level of his security and disable the cyber weapon while there is still time?


Input:

The first line will consist of the total number of test cases T. 
The next T lines will consist of one string on each line.


Output:

For each test case, output is a number.



Example:
Input:

3
aranya
reverse
gear



Output:

124
252
159
#! /usr/bin/python


# imports
import sys
import StringIO


class Problem(object):
    def __init__(self, reader):        
        self.reader = reader

    def run(self):                        
        test_case_count = int(self.reader.readline().strip())
        for test_case in range(test_case_count):
            text = self.reader.readline().strip()
            character_sum = self.get_character_sum(text)
            closest_power = self.get_closest_power_of_2(character_sum)
            print (character_sum - closest_power)

    def get_character_sum(self,  text):
        char_sum = 0
        for char in text:
            char_sum += ord(char)
            
        return int(char_sum)
            
    def get_closest_power_of_2(self,  max_limit):
        power_value = 1
        while power_value < max_limit :
            power_value *= 2
        
        return int(power_value / 2)

# Main entry point
############################################################ 
if __name__ == "__main__":

    data = sys.stdin

    problem = Problem(data)
    problem.run();