Task
Filippo loves keyboards, and he just bought a new one for his collection.
Filippo's new keyboard is made of keys arranged in a row, each containing a digit from to . Initially the digits are arranged in ascending order, i.e. the first key contains , the second key contains , and so on.
To test the new keyboard, Filippo decided to type a string . Unfortunately, he is not very good at typing, in fact he only uses a single finger to press the keys. His finger can only move left or right, one key at a time, and he can only press a key if his finger is on it. In the beginning, his finger is on the first key, i.e. the key containing .
Filippo can also swap the digits on two keys at any time (even before he starts typing), but he can only do this operation once. He does not move his typing finger while performing this operation, and he can do it even if his finger is on one of the two keys.
To get more practice, Filippo wants to type different strings . How many times does he need to move his finger to type the string ?
Note that he types the strings independently of each other, i.e., when Filippo starts typing a string, the keyboard always contains the digits from to in ascending order, and Filippo can swap the digits on two keys at most once for every string.
Input
The first line contains the only integer (), the number of strings.
The following lines contain the strings (Each string contains only digits from to ).
The length of each string is less than .
The total length of the strings does not exceed .
For tests worth points: Each string contains only different digits..
For tests worth points: The total length of the strings does not exceed .
For tests worth points: No additional limitations.
Output
You need to write lines with an integer: the minimum number of times Filippo needs to move his finger to type the string .
stdin
1
73
stdout
3
stdin
3
01234
09018
9752123
stdout
3
12
15
Notes
In the first sample case Filippo can swap the digits and before starting to type the string .
Then he can type the string by moving his finger times:
- item he moves his finger times to the right and presses the key (it now contains )
- item he moves his finger times to the right and presses the key containing
In the first case of the second sample Filippo can move his finger times in total using the following strategy:
- he presses the key containing
- he moves his finger times to the right and presses the key containing
- he moves his finger times to the right and presses the key containing
- he moves his finger times to the right and presses the key containing
- he swaps the keys containing and
- he now presses the key containing (he does not need to move his finger)