#K83937. Min Moves to Palindrome

    ID: 36308 Type: Default 1000ms 256MiB

Min Moves to Palindrome

Min Moves to Palindrome

You are given a string S. Your task is to determine the minimum number of moves required to transform S into a palindrome.

A palindrome is a string that reads the same forwards and backwards. In one move, you can change any character in the string to any other character. In this problem, the operation is optimal in the sense that for each pair of mismatched characters at symmetric positions, a single move is sufficient to make them identical.

Note: For a string of length n, you only need to consider the first ⌊n/2⌋ characters because the rest of the string mirrors these positions in a palindrome.

For example, if S = "ab", by changing either 'a' to 'b' or 'b' to 'a', the string becomes a palindrome. Therefore, the answer is 1.

inputFormat

The first line of input contains an integer T, the number of test cases. Each of the following T lines contains a string S.

Input Format:

T
S1
S2
...
ST

outputFormat

For each test case, output a single integer on a new line representing the minimum number of moves required to make the string a palindrome.

Output Format:

result1
result2
...
resultT
## sample
3
ab
aa
abcba
1

0 0

</p>