Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. 

You are given a string $S$ of lowercase English letters with length $N$. You are allowed to (but don't have to) choose one index in this string and change the letter at this index to any other lowercase English letter. The cost of this operation is the absolute value of the difference of ASCII values of the new letter and the original letter; let's denote it by $X$.

Next, consider the number of pairs of indices $(i, j)$ in the resulting string (the string after changing one letter, or the original string if no letter was changed) such that $1 ≤ i < j ≤ N$ and $S_{i} < S_{j}$. Let's denote it by $Y$.

Find the minimum possible value of $X+Y$.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains a single string $S$. 

------  Output ------
For each test case, print a single line containing one integer — the minimum value of $X+Y$.

------  Constraints  ------
$1 ≤ T ≤ 20$
$1 ≤ N ≤ 10^{5}$
$S$ contains only lowercase English letters

------  Subtasks ------
Subtask #1 (10 points): $1 ≤ N ≤ 50$

Subtask #2 (20 points): $1 ≤ N ≤ 250$

Subtask #3 (70 points): original constraints

----- Sample Input 1 ------ 
3
abcd
dbca
dcba
----- Sample Output 1 ------ 
6
1
0