
import java.util.*;

public class file {
    private static Scanner scn = new Scanner(System.in);

    private static String str;
    private static int calc(char chr, int low, int high, int cost) {
        if (low == high) {
            if (str.charAt(low) != chr) return cost+1;
            else return cost+0;
        }
        int cost1 = 0;
        for (int i = low; i <= low + (high-low)/2; i++) {
            if (str.charAt(i) != chr) cost1++;
        }
        int cost2 = 0;
        for (int j = high; j > low + ((high-low)/2); j--) {
            if (str.charAt(j) !=  chr) cost2++;
        }
        return Math.min(calc((char)(chr+1), (low + (high-low)/2)+1, high, cost+cost1), calc(((char)(chr+1)), low, low + (high-low)/2, cost+cost2));
        
    }

    private static void foo() {
        int n = scn.nextInt();
        str = scn.next();
        System.out.println(calc('a', 0, n-1, 0));
    }


    public static void main(String[] args) {
        int cas = scn.nextInt();
      // int cas = 1;
        while (cas-- > 0) foo();
    }
}


