oliver-and-strings-3

In the streets of Portugal lived a young boy named Oliver. He was the son of James and Jenny who were both Oncologists at the city hospital while his uncle Ben, worked as a lawyer in a local court at Alcácer do Sal. Oliver, being a great fan of Cristiano Ronaldo, he wanted to be the best footballer the world has ever seen.

He knows that this would take years of practice and hard work to achieve a goal as big as this. His uncle had seen Ronaldo practicing once in the field. He had a very unique practice strategy. For improving his dribbling skills and speed, he placed a ** string S** in a straight line in front of him. The beginning and the end of S were marked by the symbol $.   

This is how he practiced:
He stood at the first $, moved to the next letter in front of him, made a note of it and replaced it with $ and started running towards the end of the string and stopped at the very first $ that comes on his way. After that, he came back by one letter and compared it with the previously noted letter. If these letters are not same, he quits his practice session for the day but if they were equal, he replaces this letter by a $ symbol again and then runs towards the other end of the string unless he finds a $ and repeats the process till he is left with no letter in the string that is not a $.

Uncle Ben created very long strings and gave them as a practice set piece to Oliver. To make sure that Oliver completes the practice sessions, he gave the letters of the strings some value. The string S contains English alphabets only. Both lowercase and uppercase alphabets have a value from 1 to 26 . $ has a value = 100.
Ben asked Oliver to note down and add the values of alphabets every time he encounters them during his practice session.
Your task is to help Oliver in adding such big numbers as he good in football but not in mathematics.
Refer to the sample test cases for further clarity.

INPUT:
The first line contains a single integer T, the number of test cases.
In each of the next T lines contain a string S whose description is given above.

OUTPUT:
Display the sum that Oliver calculates for each string in a separate line.

CONSTRAINTS:
1 ≤ T ≤ 10
3 ≤ |S| ≤ 10^6  

Instructions
Write modular code  
Comment your code properly  

SAMPLE INPUT
3
$aa$
$abca$
$AbA$

SAMPLE OUTPUT
303
421
509

Explanation

Test Case #1:

$aa$ 
he starts from first $ and goes forward to a, replaces it with '$' and then moves forward until he encounters a $ ( $ + a + a + $ = 202 ). string -  a '$' . Then he comes back to 'a' (202+1 = 203) and replaces it with '$'. string -  '$' $ Then he comes all the way searching for any other character left towards the beginning of the string until he encounters a '$'. string $'$'.

SUM = 303.

Test Case #2:
$abca$
he starts from first $ and goes forward to 'a', replaces it with '$' and then moves forward until he encounters a '$'  ( $ + a + b + c + a + $ = 207 ). string -  bca'$'. Then he comes back to 'a' (207+1=208) and replaces it with $. String -  bc'$'$. Then he moves back towards the beginning until he encounters a $. String $ '$'bc ( 208 + 2 + 3 +100 = 313). He moves forward to 'b', replaces it with $ and moves towards the end. String- $c'$'$ (313+2+3+100 = 418 ) then he comes back to 'c' replaces it with $ and quits his practice as c != b ( 418 + 3 = 421 ). 

SUM = 421

test case 3
$AbA$
he starts from first $ and goes forward to 'A', replaces it with '$' and then moves forward until he encounters a '$'  ( $ + A + b + A + $ = 204 ). string -  bA'$'. Then he comes back to 'A' (204+1=205) and replaces it with $. String -  b'$'$. Then he moves back towards the beginning until he encounters a $. String $'$'b ( 208 + 1 +100 = 309). He moves forward to 'b', replaces it with $ and moves towards the end. String- $'$'$ (309+100 = 409 ) then he comes back to meet '$' and ends his practice ( 409+100=509). 

SUM = 509

Difficulty: EASY

Starter code:

Solutions: