import java.util.*;
import java.io.*;
public class q4{
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static HashMap<String,Integer> map = new HashMap<>();
    public static int func(int n, String s,char current){
    	if(n == 0){
    		return 0;
    	}
    	if(n == 1 && s.charAt(0) == current){
    		return 0;
    	}
    	if(n == 1 && s.charAt(0) != current){
    		return 1;
    	}
    	if(map.containsKey(s+" "+current)){
    		return map.get(s+" "+current);
    	}
    	int count1 = 0,count2 = 0;
    	int i = 0;
    	for(; i<(n/2); i++){
    		if(s.charAt(i)!=current){
    			count1++;
    		}
    	}
    	for(; i < n; i++){
    		if(s.charAt(i)!=current){
    			count2++;
    		}
    	}
    	int ans =  Math.min(count1 + func(n/2,s.substring(n/2),(char)((int)current+1)),
    		 count2 + func(n/2,s.substring(0,(n/2)+1),(char)((int)current+1)));
    	map.put(s+" "+current,ans);
    	return ans;
    }
	public static void main(String[] args) {
		FastReader in = new FastReader(); 
		int t = in.nextInt();
		for(int z = 0; z < t; z++){
			int n = in.nextInt();
			String s = in.next();
			System.out.println(func(n,s,'a'));
		}
	}
}