keyboard

Time limit: 0.5s Memory limit: 64MB Input: Output:

Task

Filippo loves keyboards, and he just bought a new one for his collection.

Filippo's new keyboard is made of 1010 keys arranged in a row, each containing a digit from 00 to 99. Initially the digits are arranged in ascending order, i.e. the first key contains 00, the second key contains 11, and so on.

To test the new keyboard, Filippo decided to type a string SS. 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 00.

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 TT different strings S1,S2,,STS_1, S_2, \dots, S_T. How many times does he need to move his finger to type the string SiS_i?

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 00 to 99 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 TT (1T20 0001 \le T \le 20\ 000), the number of strings.
The following TT lines contain the strings S1,S2,,STS_1, S_2, \dots, S_T (Each string SiS_i contains only digits from 00 to 99).

The length of each string is less than 100 000100\ 000.

The total length of the strings does not exceed 100 000100\ 000.

For tests worth 3030 points: Each string SiS_i contains only 22 different digits..

For tests worth 3030 points: The total length of the strings does not exceed 10001000.

For tests worth 4040 points: No additional limitations.

Output

You need to write TT lines with an integer: the minimum number of times Filippo needs to move his finger to type the string SiS_i.

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 22 and 77 before starting to type the string 7373.
Then he can type the string by moving his finger 33 times:

  • item he moves his finger 22 times to the right and presses the key (it now contains 77)
  • item he moves his finger 11 times to the right and presses the key containing 33

In the first case of the second sample Filippo can move his finger 33 times in total using the following strategy:

  • he presses the key containing 00
  • he moves his finger 11 times to the right and presses the key containing 11
  • he moves his finger 11 times to the right and presses the key containing 22
  • he moves his finger 11 times to the right and presses the key containing 33
  • he swaps the keys containing 33 and 44
  • he now presses the key containing 44 (he does not need to move his finger)

Log in or sign up to be able to send submissions!