import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		
		FastReader in = new FastReader();
		int T = in.nextInt();
		for (int index = 0; index < T; index++) {
			int l = in.nextInt();
			String s = in.next();
			l = Math.min(evaluate(s, 'a'), l);
			System.out.println(l);
		}
	}
	
	public static int evaluate(String s, char c) {
		//System.out.println(s + " " + c);
		if (isGood(s, c)) {
			return 0;
		}
		if (s.length() == 1) {
			return 1;
		}
		
		int halfCheck1 = 0;
		int halfCheck2 = 0;
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != c) {
				halfCheck1 += 1;
			}
		}
		for (int i = s.length() / 2; i < s.length(); i++) {
			if (s.charAt(i) != c) {
				halfCheck2 += 1;
			}
		}
		
		halfCheck2 += evaluate(s.substring(0, s.length() / 2), (char) ((int)c + 1));
		halfCheck1 += evaluate(s.substring(s.length() / 2, s.length()), (char) ((int)c + 1));
		
		
		return Math.min(halfCheck1, halfCheck2);
	}
	
	public static boolean isGood(String s, char c) {
		if (s.length() == 1) {
			return s.charAt(0) == c;
		}
		boolean halfCheck1 = true;
		boolean halfCheck2 = true;
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != c) {
				halfCheck1 = false;
			}
		}
		for (int i = s.length() / 2; i < s.length(); i++) {
			if (s.charAt(i) != c) {
				halfCheck2 = false;
			}
		}
		if (halfCheck1) {
			return isGood(s.substring(s.length() / 2, s.length()), (char) ((int)c + 1));
		}
		if (halfCheck2) {
			return isGood(s.substring(0, s.length() / 2), (char) ((int)c + 1));
		}
		return false;
	}
	
	
	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()); 
        } 
    }

}

 		  		 					 	  			     	 			