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

public class D_1385 {
	
	static int[][] diff;
	
	public static int get(int i, int j, char c) {
		if(i == 0)
			return diff[c - 'a'][j];
		else
			return diff[c - 'a'][j] - diff[c - 'a'][i - 1];
	}
	
	public static int bt(int i, int j, char c) {
		if(i == j)
			return get(i, j, c);
		int mid = (i + j) / 2;
		return Math.min(get(i, mid, c) + bt(mid + 1, j, (char)(c + 1)), get(mid + 1, j, c) + bt(i, mid, (char)(c + 1)));
	}
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int t = sc.nextInt();
		while(t-->0) {
			int n = sc.nextInt();
			String s = sc.next();
			
			diff = new int[26][n];
			for(int i = 0; i < 26; i++)
				for(int j = 0; j < n; j++)
					if(s.charAt(j) != (char)('a' + i))
						diff[i][j] = 1;
					else
						diff[i][j] = 0;
			
			for(int i = 0; i < 26; i++)
				for(int j = 1; j < n; j++)
					diff[i][j] += diff[i][j - 1];
			
			pw.println(bt(0, n - 1, 'a'));
		}
		
		pw.flush();
	}

	public static 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 char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public static int[] shuffle(int[] a) {
			int n = a.length;
			Random rand = new Random();
			for (int i = 0; i < n; i++) {
				int tmpIdx = rand.nextInt(n);
				int tmp = a[i];
				a[i] = a[tmpIdx];
				a[tmpIdx] = tmp;
			}
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}
