import java.util.HashMap;
import java.util.Scanner;

public class AGoodString {
    public static void main(final String[] parameters) {
        Scanner input = new Scanner(System.in);
        int totalCases = input.nextInt();

        while (totalCases-- > 0) {
            int stringLength = input.nextInt();
            String string = input.next();
            HashMap<String, Integer> substringToConversions = new HashMap<>();
            int numberOfConversions = findNumberOfConversions(string, 0, string.length() - 1, 'a', substringToConversions);

            System.out.println(numberOfConversions);
        }
    }

    static int findNumberOfConversions(final String string, int startIndex, int endIndex, final char targetCharacter, final HashMap<String, Integer> substringToConversions) {
        if (startIndex == endIndex) {
            return string.charAt(startIndex) == targetCharacter ? 0 : 1;
        }

        String substring = startIndex + " " + endIndex + " " + targetCharacter;

        if (substringToConversions.containsKey(substring)) {
            return substringToConversions.get(substring);
        }

        int leftConversions = 0;
        int rightConversions = 0;
        int startIndexDuplicate = startIndex;
        int middleIndex = startIndex + (endIndex - startIndex) / 2;
        int endIndexDuplicate = endIndex;

        while (startIndex < endIndex) {
            if (string.charAt(startIndex++) != targetCharacter) {
                leftConversions++;
            }

            if (string.charAt(endIndex--) != targetCharacter) {
                rightConversions++;
            }
        }

        int optionOne = leftConversions + findNumberOfConversions(string, middleIndex + 1, endIndexDuplicate, (char) (targetCharacter + 1), substringToConversions);
        int optionTwo = rightConversions + findNumberOfConversions(string, startIndexDuplicate, middleIndex, (char) (targetCharacter + 1), substringToConversions);
        int numberOfConversions = Math.min(optionOne, optionTwo);

        substringToConversions.put(substring, numberOfConversions);
        return numberOfConversions;
    }
}

/*
6
8
bbdcaaaa
8
asdfghjk
8
ceaaaabb
8
bbaaddcc
1
z
2
ac
 */
