#c22602. a-Good String

a-Good String

a-Good String

Problem Source

CF 1385D

Problem Description

You are given a string ss of length nn consisting of lowercase letters, and n=2kn = 2^k where kk is a non-negative integer.

A non-empty string ss is called cc-goodgood (cc is some letter from aa to zz) if it satisfies one of the following three conditions:

  • ss has length 11 and contains only the character cc;
  • ss has length greater than 11, the first half of ss consists entirely of character cc, and the second half is a next(c)next(c)-goodgood string, where next(c)next(c) is the letter following cc;
  • ss has length greater than 11, the first half is a next(c)next(c)-goodgood string, and the second half consists entirely of character cc;

For example, aabc is a-goodgood, and ffgheeee is e-goodgood.

For the given string ss, find the minimum number of characters you need to change in ss to make it an a-goodgood string.

Input Format

There are multiple test cases.

The first line contains an integer TT, the number of test cases.

Each test case consists of two lines: the first line contains an integer nn, and the second line contains a string ss of length nn.

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 100%100\% of the data, 1≤T≤5,1≤n≤1310721 \leq T \leq 5, 1 \leq n \leq 131072, and n=2kn = 2^k where kk is a non-negative integer.