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

public class Main {
	static Scanner sc = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	static char arr[];
	
	static int solve(int l, int r, int c) {
		if(l == r) {
			return arr[l] - 'a' == c ? 0 : 1;
		}
		
		int lecost = 0, ricost = 0, mid = (l + r) >> 1;
		for(int i = l; i <= r; i++) {
			if(i <= mid) {
				lecost += arr[i] - 'a' == c ? 0 : 1;
			}else {
				ricost += arr[i] - 'a' == c ? 0 : 1;
			}
		}
		
		int le = solve(mid + 1, r, c + 1) + lecost;
		int ri = solve(l, mid, c + 1) + ricost;
		return Math.min(le, ri);
	}

	public static void main(String[] args) throws Exception {
		int t = sc.nextInt();
		while(t-- > 0) {
			int n = sc.nextInt();
			arr = sc.nextLine().toCharArray();
			out.println(solve(0, n - 1, 0));
		}
		out.close();
	}
}


class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream system) {
		br = new BufferedReader(new InputStreamReader(system));
	}

	public Scanner(String file) throws Exception {
		br = new BufferedReader(new FileReader(file));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public Long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}