//package codeforces;

import java.util.Scanner;

public class AGoodString {

    public int rec(String s, int n, char c) {

        if(s.length() == 0) {
            return 0;
        }
        if(s.length() == 1 && s.charAt(0)!=c) {
            return 1;
        } else {
            if(s.length() == 1 && s.charAt(0) == c) {
                return 0;
            }
        }
        return Math.min(cost(s.substring(0, s.length()/2), c) + rec(s.substring(s.length()/2 ), n,(char)(c+1))
        , cost(s.substring(s.length()/2 ), c)+ rec(s.substring(0, s.length()/2),n, (char)(c + 1)));
    }
    public int cost(String s, char c) {
        int count = 0;
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == c) {
                count++;
            }
        }
        return s.length() - count;
    }
    public void print(String s) {

        System.out.println(rec(s, s.length(), 'a'));
    }
    public static void main(String []args) {

        Scanner sc = new Scanner(System.in);
        AGoodString l = new AGoodString();
        int n = sc.nextInt();
        while ( n > 0) {
            int p = sc.nextInt();
            String s = sc.next();
            l.print(s);
            n--;
        }
    }
}
