#c22602. a-Good String
a-Good String
a-Good String
Problem Source
CF 1385D
Problem Description
You are given a string of length consisting of lowercase letters, and where is a non-negative integer.
A non-empty string is called - ( is some letter from to ) if it satisfies one of the following three conditions:
- has length and contains only the character ;
- has length greater than , the first half of consists entirely of character , and the second half is a - string, where is the letter following ;
- has length greater than , the first half is a - string, and the second half consists entirely of character ;
For example, aabc is a-, and ffgheeee is e-.
For the given string , find the minimum number of characters you need to change in to make it an a- string.
Input Format
There are multiple test cases.
The first line contains an integer , the number of test cases.
Each test case consists of two lines: the first line contains an integer , and the second line contains a string of length .
Output Format
For each test case, output one line containing an integer: the answer.
Sample Input
5
8
bbdcaaaa
8
asdfghjk
8
ceaaaabb
8
bbaaddcc
1
z
Sample Output
0
7
4
5
1
Constraints
For of the data, , and where is a non-negative integer.