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


import java.io.*;
	

	
public class cf {
	static InputReader obj = new InputReader(System.in);
	static long mod = (long)1e9+7;
	public static void main(String args[]) {
		main();
	}
	
	static void main() {
		int t=obj.nextInt();
		while(t-->0) {
			int n=obj.nextInt();
			String string = obj.next();
			char arr[] = string.toCharArray();
			//input(arr, n);
			System.out.println(check(arr, 0, n-1, 'a'));
		}
	}
	
	public static int check(char arr[], int i, int j, char c) {
		if(i==j) return arr[i]==c ? 0 : 1;
		int temp1=0;
		int temp2=0;
		int ans=0;
		for(int k=i;k<=(i+j)/2;k++) {
			if(arr[k]!=c) temp1++;
		}
		for(int k=(i+j+1)/2;k<=j;k++) {
			if(arr[k]!=c) temp2++;
		}
		if(temp1<temp2) {
			ans=check(arr, (i+j+1)/2, j, (char)(c+1))+temp1;
		}
		else if(temp1>temp2) {
			ans=check(arr, i, (i+j)/2, (char)(c+1))+temp2;
		}
		else {
			ans = temp1+Math.min(check(arr, (i+j+1)/2, j, (char)(c+1)), check(arr, i, (i+j)/2, (char)(c+1)));
		}
		return ans;
		
	}
	
	public static void input(int arr[], int n) {
		for(int i=0;i<n;i++) {
	    	arr[i] = obj.nextInt();
	    }
	}
	
	public static class InputReader {
	    public BufferedReader reader;
	    public StringTokenizer tokenizer;
	    public InputReader(InputStream stream) {
	        reader = new BufferedReader(new InputStreamReader(stream), 32768);
	        tokenizer = null;
	    }
 
	    public String next() {
	        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }
 
	    public int nextInt() {
	        return Integer.parseInt(next());
	    }
 
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	}

}
