import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		StringBuilder sb=new StringBuilder();
		
		int t=s.nextInt();
		
		for(int i=0;i<t;i++)
		{
			int n=s.nextInt();
			
			String str=s.next();
			
			int[][] dp=new int[26][n];
			
			dp[str.charAt(0)-'a'][0]++;
			
			for(int j=1;j<n;j++)
			{
				for(int k=0;k<26;k++)
				{
					if(str.charAt(j)-'a'==k)
					{
						dp[k][j]=dp[k][j-1]+1;
					}
					else
					{
						dp[k][j]=dp[k][j-1];
					}
				}
			}
			
			int ans=fun(str,0,n-1,dp,0);
			sb.append(ans);
			sb.append("\n");
			
		}
		
		System.out.println(sb);
		
	}
	
	public static int fun(String str,int start,int end,int[][] dp,int ch)
	{
		if(start==end)
		{
			if(str.charAt(start)-'a'==ch)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		int mid=(start+end)/2;
		
		int p=0;
		
		if(str.charAt(start)-'a'==ch)
			p=1;
		
		int ans1=(mid-start+1)-(p+dp[ch][mid]-dp[ch][start])+fun(str,mid+1,end,dp,ch+1);
		
		int ans2=(end-mid)-(dp[ch][end]-dp[ch][mid])+fun(str,start,mid,dp,ch+1);
		
		return Math.min(ans1, ans2);
		
	}
	
}