
The first line of the input contains a single integer 'T', representing the number of test cases.
The first line of each test case contains a string ‘STR’.
For each test case, print a single integer representing the number of swaps required to convert a string into the palindrome or “-1” if it is impossible to convert it into a palindrome.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= |STR| <= 10^3
The string ‘STR’ contains small letters only.
Time Limit : 1 sec
The basic idea is first to check whether the count of letters present in the string is even or not. A palindrome can maximum consist of 1 odd count letter. Example: madam, pikkkip. Then we can use a two-pointer approach to check for the first letter and last letter simultaneously. If they match, we move forward or count the number of swaps required to make them equal.
Here is the algorithm :