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


public class ProblemD {
	
	//static long globalCount = 0L;
	
	public static void main(String[] args) throws IOException {
		InputStream in = System.in;
		InputReader scan = new InputReader(in);
		int test = scan.nextInt();
		StringBuilder res = new StringBuilder();
		for(int t=0;t<test;t++) {
			//globalCount = 0L;
			int n = scan.nextInt();
			String str = scan.next();
			int result = getMin(0,n-1,'a',str);
			res.append(result).append("\n");
		}
		System.out.print(res);
	}
	
	static int getMin(int start, int end, char ch, String str) {
		if(start==end) {
			if(str.charAt(start)==ch) return 0;
			else return 1;
		}
		int halfSize = (end-start+1)/2;
		int firstHalfDiff = 0;
		for(int i=start;i<=start+halfSize-1;i++) {
			if(str.charAt(i)!=ch) firstHalfDiff++;
			//globalCount++;
		}
		int secondHalfDiff = 0;
		for(int i=start+halfSize;i<=end;i++) {
			if(str.charAt(i)!=ch) secondHalfDiff++;
			//globalCount++;
		}
		return Math.min(getMin(start,start+halfSize-1,(char)(ch+1),str) + secondHalfDiff
				,firstHalfDiff + getMin(start+halfSize,end,(char)(ch+1),str));
	}
	
	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		InputReader(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException ioe) {
					ioe.printStackTrace();
				}
			}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}
