import java.io.*;
import java.util.*;

public class Main {

    static int find(char[] arr, int c, int st, int en){
        if(en==st) return (arr[en] == (char)c)?0:1;
        int ans1 = 0;
        for(int i = st; i<=(st+en)/2; i++){
            if(arr[i] != (char)(c)) ans1++;
        }
        ans1 += find(arr, c+1, (en+st+1)/2, en);
        int ans2 = 0;
        for(int i = en; i>(st+en)/2; i--){
            if(arr[i]!= (char)c) ans2++;
        }
        ans2 += find(arr, c+1, st, (st+en)/2);
        return Math.min(ans1, ans2);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int tst = Integer.parseInt(br.readLine());
        while(tst-->0){
            int n = Integer.parseInt(br.readLine());
            char[] arr = br.readLine().toCharArray();
            int ans = find(arr, 97, 0, n-1);
            System.out.println(ans);
        }
    }
}