

You are given a string STR of length N consisting of lowercase English Alphabet letters. Your task is to return the count of minimum characters to be added at front to make the string a palindrome.
For example:
For the given string “deed”, the string is already a palindrome, thus, minimum characters needed to be added are 0.
Similarly, for the given string “aabaaca”, the minimum characters needed are 2 i.e. ‘a’ and ‘c’ which makes the string “acaabaaca”, which is a palindrome.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first and only line of each test case contains the string STR.
Output format:
For each test case, print the count of minimum characters needed to make the string palindrome.
Output for each test case will be printed in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 5000
STR contains only lowercase English letters.
Time limit: 1 second
2
abcd
dad
3
0
For test case 1:
Minimum characters to be added at front to make it a palindrome are 3 i.e. “dcb” which makes the string “dcbabcd”.
For test case 2:
The string is already a palindrome, we do not need to add any character.
2
xxaxxa
abb
1
2
First off, observe that the question focuses on the terms palindrome and addition at front.
O(N ^ 2) per test case, where N is the size of the given string.
In the worst case, we are checking N times if the string is a palindrome. This takes linear time in each check.
O(1) per test case.
In the worst case, only constant extra space is used.