

A palindrome is a word, number, phrase, or another sequence of characters that reads the same backward as forward, such as “madam” or “racecar”.
Given an ‘STR’: ‘aaaaaaa’ The minimum characters that will be replaced are 4. The string can be converted into ‘abcabca’.
Here are multiple possible answers, for example changing all the elements, but we have to find the minimum replacements possible.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a string that represents the input string ‘STR’.
For each test case, print an integer denoting the minimum characters that can be replaced such that the string does not contain any palindromic substring of length 1.
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 10^2
1 <= |STR| <= 10^3
Time Limit: 1 sec
The basic idea of this approach is to remove all the palindromes of length two and three. The idea is that if there exists a palindromic substring larger than length 3 then a palindrome of length 2 or 3 is present.
Here is the algorithm: