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

public class D {

	PrintWriter out;
	int maxgood;

	public static void main(String[] args) throws Exception {
		new D().run();
	}

	public void run() throws Exception {
		FastScanner file = new FastScanner();
		out = new PrintWriter(System.out);

		int times = file.nextInt();
		for (int asdf = 0; asdf < times; asdf++) {
			int ln = file.nextInt();
			String thing = file.next();
			maxgood = Integer.MIN_VALUE;
			out.println(ln - recur(thing, 'a'));
			/*int cntbegin = 0, cntend = 0;
			char curr = 'a';
			int half = ln / 2, keephalf = half;
			for (int i = 0; i < ln; i++) {
				if (thing.charAt(i) == curr)
					cntbegin++;
				half--;
				if (half == 0) {
					keephalf /= 2;
					half = keephalf;
					curr++;
				}
			}
			curr = 'b';
			half = ln / 4;
			keephalf = half;
			for (int i = 0; i < ln / 2; i++) {
				if (thing.charAt(i) == curr)
					cntend++;
				half--;
				if (half == 0) {
					keephalf /= 2;
					half = keephalf;
					curr++;
				}
			}
			for (int i = ln / 2; i < ln; i++) {
				if (thing.charAt(i) == 'a')
					cntend++;
			}
			out.println(cntbegin + " " + cntend);
			out.println(ln - Math.max(cntbegin, cntend));*/
		}

		file.close();
		out.flush();
	}
	
	int recur(String thing, char curr) {
		if (thing.length() == 1)
			return thing.charAt(0) == curr ? 1 : 0;
		int cntbegin = 0, cntend = 0;
		for (int i = 0; i < thing.length(); i++) {
			if (thing.charAt(i) == curr) {
				if (i < thing.length() / 2)
					cntbegin++;
				else
					cntend++;
			}
		}
		curr++;
		return Math.max(cntbegin + recur(thing.substring(thing.length() / 2), curr), recur(thing.substring(0, thing.length() / 2), curr) + cntend);
	}

	static class FastScanner {

		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 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());
		}

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

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

		public void close() throws IOException {
			reader.close();
		}
	}
}