import java.util.*;
public class prac {
  static Scanner sc = new Scanner(System.in);
  public static void main(String args[]) {
    int t=sc.nextInt();
    sc.nextLine();
    while(t-->0)
    {
      int n=sc.nextInt();
      sc.nextLine();
      String s=sc.nextLine();
      int l=0,r=n-1;
      if(l==r)
      {
        if(s.charAt(0)=='a')
        System.out.println(0);
        else
        System.out.println(1);
        continue;
      }
      char c='a';
      int ans=0;
      while(l<=r)
      {
        int ct=0;
        int mid=l+(r-l)/2;
        int[] a=new int[n];
        for(int i=l;i<=r;i++)
        {
          if(s.charAt(i)==c)
          {
            ct++;
          }
          a[i]=ct;
        }
        if(a[mid]>=a[r]-a[mid])
        {
            ans+=(mid-l+1)-(a[mid]);
            l=mid+1;
        }
        else{
          ans+=(r-mid)-(a[r]-a[mid]);
          r=mid;
        }
        c++;
      }
      System.out.println(ans);
    }
  }
  }
