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

public class File {
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            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());
        }
    }
	
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		
		
		
		int T = sc.nextInt();
		
		for (int t = 1; t <= T; t++) {
			int n = sc.nextInt();
			String s = sc.next();
			
			int[][] pre = new int[n][26];
			
			for (int i = 0; i < n; i++) {
				char c = s.charAt(i);
				
				if (i > 0) {
					for (int j = 0; j < 26; j++) {
						pre[i][j] = pre[i-1][j];
					}
				}
				
				pre[i][c-'a']++;
			}
			
			out.println(makeGood(s, 0, n-1, 0, pre));
		}
		
		
		
		
		out.close();
	}
	
	public static int makeGood(String s, int lo, int hi, int c, int[][] pre) {
		if (lo == hi) {
			if ((s.charAt(lo) - 'a') == c) {
				return 0;
			}
			else {
				return 1;
			}
		}		
				
		int leftCost = 0;
		int rightCost = 0;
		int halfN = (hi - lo + 1) / 2;
		
		int mid = lo + (hi - lo) / 2;
		
		// Make left half into all c.
		int leftC = pre[mid][c] - (lo > 0 ? pre[lo-1][c] : 0);
		leftCost = (halfN - leftC) + makeGood(s, mid+1, hi, c+1, pre);
		
		// Make right half into all c.
		int rightC = pre[hi][c] - pre[mid][c];
		rightCost = (halfN - rightC) + makeGood(s, lo, mid, c+1, pre);
		
		// System.out.println(lo + ", " + hi + ": " + c + "::" + leftC + "; " + rightC);
		
		// System.out.println(lo + "-" + hi + ": " + c + "::" + leftCost + ", " + rightCost);
		
		return Math.min(leftCost, rightCost);
	}
}











	