#P14225. [ICPC 2024 Kunming I] 左移 2
[ICPC 2024 Kunming I] 左移 2
Problem Description
Given a string consisting of lowercase letters, we say the string is beautiful if every pair of adjacent characters in the string are different. For example, and are beautiful, but is not, because its -rd and -th characters are the same.
Given a string of length consisting of lowercase English letters, let denote the string obtained by shifting left by positions. That is, $f(S, d) = s_{(d+0)\bmod n}s_{(d+1)\bmod n}\cdots s_{(d+n-1)\bmod n}$.
Let denote the minimum number of operations needed to make beautiful. In each operation, you may change any single character of into any lowercase letter.
Find a non-negative integer that minimizes , and output this minimum value.
Input Format
There are multiple test cases. The first line contains an integer , the number of test cases. For each test case:
The first line contains a string consisting only of lowercase letters ().
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output one line with one integer, the minimum value of .
3
abccbbbbd
abcde
x
2
0
0
Hint
For the first sample case, consider . We have . For this string, we can change its -nd character into , and change its -th character into . Then the string becomes , which is a beautiful string.
Translated by QwenWork