import java.util.*;
import java.io.*;
public class d {
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int T = sc.nextInt();
		
		while(T-- > 0) {
			int n = sc.nextInt();
			StringBuilder str = new StringBuilder(sc.next());

			out.println(go(str, 'a'));
			
		}
		
		out.close();
	}
	
	static int go(StringBuilder sb, char let) {
		int n = sb.length();
		if (n == 1) {
			 return numDiff(sb, let);
		}
		StringBuilder left = new StringBuilder(sb.substring(0, n/2));
		StringBuilder right = new StringBuilder(sb.substring(n/2));
		// left this letter
		int res = numDiff(left, let) + go(right, (char)(let+1));
		
		// right this letter
		res = Math.min(res, numDiff(right, let) + go(left, (char)(let+1)));
		//System.out.println(let + " " + res + " " + sb.toString());
		return res;
	}
	
	static int numDiff(StringBuilder sb, char let) {
		int ct = 0;
		for (int i = 0 ; i < sb.length() ; i++) {
			if (sb.charAt(i) != let) {
				ct++;
			}
		}
		
		return ct;
	}

	static class FastScanner {
	    BufferedReader br;
	    StringTokenizer st;
		
	    public FastScanner(InputStream i) {
	        br = new BufferedReader(new InputStreamReader(i));
	        st = new StringTokenizer("");
	    }
				
	    public String next() throws IOException {
	        if(st.hasMoreTokens())
	            return st.nextToken();
	        else
	            st = new StringTokenizer(br.readLine());
	        return next();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    public long nextLong() throws IOException {
	        return Long.parseLong(next());
	    }
	    public double nextDouble() throws IOException {
	        return Double.parseDouble(next());
	    }
	}
}
