题目描述
Emily and Mia are friends. Emily got Mia’s essay paper, but since she is a prankster, she decided to meddle with the words present in the paper. She changes all the words in the paper into palindromes. To do this, she follows two rules:
- In one operation she can only reduce the value of an alphabet by 1, i.e. she can change ‘d’ to ‘c’, but she cannot change ‘c’ to ‘d’ or ‘d’ to ‘b’.
- The alphabet ‘a’ will not be reduced any further.
Each reduction in the value of any alphabet is counted as a single operation. Find the minimum number of operations required to convert a given string into a palindrome.
-----Input:-----
- The first line contains an integer $T$, denoting the number of test cases.
- Each test case consists of a string $S$ containing only lowercase characters with no spaces.
-----Output:-----
For each test case on a new line, print the minimum number of operations for the corresponding test case.
-----Constraints-----
- $1<=T<=10$
- $1<=|S|<=10^7$, where $|S|$ denotes length of string S.
-----Sample Input:-----
4
abc
abcba
abcd
cba
-----Sample Output:-----
2
0
4
2
-----EXPLANATION:-----
For the first test case string = “abc”
c->b->a so the string become “aba” which is a palindrome. For this we perform 2 operations
输入格式
见题面
输出格式
见题面