Sweety and Printer
All submissions for this problem are available.Sweety has bought a new printer for writing a book. The printer prints in a unique way. It has alphabets arranged in a circular way and makes rotations to reach the desired alphabet. Since Sweety wants to print so many letters and the printer takes time in rotations, she wants to minimize the number of rotations for the printer. She needs to program the printer to take the shorter path for every alphabet. For example, suppose the printer is at letter 'B' and she wants to print 'Z' next. Either the printer takes 24 rotations through 'C', 'D' ... and so on till 'Z', or it just takes 2 rotations through 'A' and then 'Z'. Given a string $S$, print the **minimum number of rotations** needed for the printer. **Note: Assume that the printer is at 'A' in its initial position in each test case.** ### Input - First line of input contains a single integer $T$ denoting the number of test cases. - The only line of each test case contains a string $S$ consisting of upper-case English alphabets. ### Output For each test case, print the required answer in a new line. ### Constraints - $1 \le T \le 10^3$ - $1 \le length\_of\_S \le 10^4$ ### Example Input ``` 2 HELLO BYE ``` ### Example Output ``` 20 10 ``` ### Explanation **Case 1:** Initially at 'A' - Goes to 'H' in 7 clockwise rotations. - Goes to 'E' in 3 anti-clockwise rotations. - Goes to 'L' in 7 clockwise rotations. - Goes to 'L' in 0 rotations. - Goes to 'O' in 3 clockwise rotations. **Case 2:** Initially at 'A' - Goes to 'B' in 1 clockwise rotation. - Goes to 'Y' in 3 anti-clockwise rotations. - Goes to 'E' in 6 clockwise rotations.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions