/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	     Scanner in=new Scanner(System.in);
	     int n,i,j,k,t,l,r;
	     int x,y,p,h,m,f;
	     String s,st;//toCharArray();
	     //length();
	     //nextInt //next
	     //substring
	     t=in.nextInt();
	     for(k=0;k<t;k++)
	     {
	          n=in.nextInt();
     	     s=in.next();
     	     char a[]=s.toCharArray();
     	     if(n==1 && a[0]=='a')
                    x=0;
               else if(n==1)
                    x=1;
               else
               {
                    char c='a';
                    x=0;p=0;h=0;
                    for(i=0;i<n/2;i++)
                    {
                         if(a[i]!=c)
                              p++;
                    }
                    for(i=n/2;i<n;i++)
                    {
                         if(a[i]!=c)
                              h++;
                    }
                    while(n>0)
                    {
                         if(p<=h)
                         {
                              x=x+p;
                              s=s.substring(n/2,n);
                         }
                         else
                         {
                              x=x+h;
                              s=s.substring(0,n/2);
                         }
                         n=n/2;
                         c++;
                         char a1[]=s.toCharArray();
                         if(n==1)
                         {
                              if(a1[0]!=c)
                                   x++;
                              break;
                         }
                         p=0;h=0;
                         for(i=0;i<n/2;i++)
                         {
                              if(a1[i]!=c)
                                   p++;
                         }
                         for(i=n/2;i<n;i++)
                         {
                              if(a1[i]!=c)
                                   h++;
                         }
                    }
               }
               System.out.println(x);
	     }
	}
}