Primitive Typing
Submissions: 770   Accuracy:

27.35%

  Difficulty: Easy   Marks: 2

Given a screen containing alphabets from a-z, we can go from one character to another character using a remote. The remote contains left, right, top and bottom keys.

Remote :

Find the shortest possible path to type all characters of given string using the remote. The initial position is top left and all characters of input string should be printed in order. Print the total number of moves in such a path(Move UP, DOWN, LEFT, RIGHT). Pressing OK also accounts for one move.

Screen:

a b c d e
f g h i j
k l m n o
p q r s t
u v w x y
z

Input:
The first line contains an integer T which is the number of test cases. Each test case contains a string s.

Output:
Print the number of minimum moves required to print the string s.

Constraints:
1<=T<=100
1<=|s|<=100

Example:
Input:

2
cozy
a

Output:
24
9

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Shashwat Jain
Author: shashwat jain


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.