// package Self;

import java.util.Scanner;
import java.util.Set;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.concurrent.Callable;
import java.util.Queue;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;

public class Main {

	static FastReader scn = new FastReader();

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args) {

		StringBuilder sb = new StringBuilder();

		int t = scn.nextInt();

		while (t-- > 0) {

			int n = scn.nextInt();
			String str = scn.next();

			sb.append(find(0, n - 1, str, 'a') + "\n");

		}

		System.out.println(sb.toString());

	}

	private static int find(int lo, int hi, String str, char ch) {

		if (lo == hi) {
			return str.charAt(lo) == ch ? 0 : 1;
		}

		int mid = (lo + hi) / 2;

//		lo to mid
//		mid+1 to hi

		int[] f1 = new int[26];
		int[] f2 = new int[26];

		for (int i = lo; i <= mid; i++)
			f1[str.charAt(i) - 'a']++;

		for (int i = mid + 1; i <= hi; i++)
			f2[str.charAt(i) - 'a']++;

		int half = 0;
		boolean first = true;

		for (int i = 0; i < 26; i++) {

			if (ch - 'a' + i >= 26)
				break;

			int idx = (ch - 'a' + i) % 26;

			int v1 = f1[idx];
			int v2 = f2[idx];

			if (i > 0)
				first = false;

			if (v1 > v2) {
				half = 1;
				break;
			}

			else if (v2 > v1) {
				half = 2;
				break;
			}

		}

		int ans = 0;
		int curLen = hi - lo + 1;

		if (half <= 1) {
			if (first) {
				ans += (curLen / 2) - f1[ch - 'a'];
				ans += find(mid + 1, hi, str, (char) (ch + 1));
			}

			else {
				ans += (curLen / 2) - f2[ch - 'a'];
				ans += find(lo, mid, str, (char) (ch + 1));
			}
		}

		else if (half == 2) {
			if (first) {
				ans += (curLen / 2) - f2[ch - 'a'];
				ans += find(lo, mid, str, (char) (ch + 1));
			}

			else {
				ans += (curLen / 2) - f1[ch - 'a'];
				ans += find(mid + 1, hi, str, (char) (ch + 1));
			}
		}

		return ans;

	}

	public static int[] input(int n) {

		int[] arr = new int[n];

		for (int i = 0; i < n; i++) {
			arr[i] = scn.nextInt();
		}

		return arr;

	}

}
