//package codeforces.r656_1385;

import java.util.Scanner;

public class D_AGoodString {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for (int i = 0; i < T; i++) {
            int n = scanner.nextInt();
            String s = scanner.next();
            System.out.println(getMinMoves(n, s));
        }
    }

    private static int getMinMoves(int n, String s) {
        return getMinMoves(s, 0, s.length() - 1, 'a');
    }

    private static int getMinMoves(String s, int start, int end, char c) {
        if (start == end) {
            return c == s.charAt(start) ? 0 : 1;
        }
        int mid = (start + end) / 2;
        int firstHalfMisMatch = 0;
        int secondHalfMismatch = 0;
        for (int i = start; i <=mid; i++) {
            if (s.charAt(i) != c) firstHalfMisMatch++;
        }
        for (int i = mid+1; i <= end ; i++) {
            if (s.charAt(i) != c) secondHalfMismatch++;
        }
        int leftMoves = getMinMoves(s, start, mid, (char)(c+1)) + secondHalfMismatch;
        int rightMoves = getMinMoves(s, mid+1, end, (char)(c+1)) + firstHalfMisMatch;
        return Math.min(leftMoves, rightMoves);
    }
}
