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

public class scratch
{
	static int solve(char[] a, int low, int high, char c)
	{
		if(low == high)
		{
			if(a[low] == c) return 0;
			else return 1;
		}

		int mid = low + (high-low)/2;
		int right = 0, left = 0;
		for(int i=mid+1; i<=high; i++)
		{
			if(a[i] != c) right++;
		}

		for(int i=low; i<=mid; i++)
		{
			if(a[i] != c) left++;
		}
		char x = ++c;
		return Math.min(left + solve(a, mid+1, high, x), right + solve(a, low, mid, x));
	}
	public static void main(String[] args)
	{
		FastReader reader = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int t = reader.nextInt();
		while (t-- > 0)
		{
			int n = reader.nextInt();
			char[] a = reader.next().toCharArray();
			out.println(solve(a, 0, n-1, 'a'));
		}

		out.close();
	}

	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;
		}
	}
}

