/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Hp
 */
import java.io.*;
import java.util.*;
public class ProblemD {
    public static int minMoves(String s,char ch, int start,int end, int n){
        if(n == 0)
            return 0;
        if(n == 1){
            if(s.charAt(start) == ch)
                return 0;
            return 1;
        }
        
        //2 or higher
        int mid = start + n/2;
        int left = minMoves(s,(char)(ch + 1),start,mid-1,n/2);
        int right = minMoves(s,(char)(ch + 1),mid,end,n/2);
        
        int leftCount = 0;
        int rightCount = 0;
        for(int i = start; i < mid;i++){
            if(s.charAt(i) != ch)
                leftCount++;
        }
        for(int i = mid; i <= end;i++){
            if(s.charAt(i) != ch)
                rightCount++;
        }
        //System.out.println(ch + "," + start + "," + end + "," + left + "," + right);
        //System.out.println(leftCount + "," + rightCount);
        leftCount += right;
        rightCount += left;
        
        return Math.min(leftCount,rightCount);    
    }
    public static void main(String args[])throws IOException{
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while(t > 0){
            int n = sc.nextInt();
            String s = sc.next();
            int min = minMoves(s,'a',0,n-1,n);
            System.out.println(min);
            t--;
        }
    }
}
