/*input
5 5 2 3



*/
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
 {
 static Scanner in = new Scanner(System.in);
 
    
    public static int tot(String s,int n,int c)
    {
        if(n==1)
        {
            if(s.charAt(0)==c)
            return 0;
            return 1;
        }
        int first=0,last=0;
        
        for(int i=0;i<n;i++)
        {
            if(s.charAt(i)!=c)
            {
                if(i<n/2)
                first++;
                else
                last++;
            }
        }
        
        
        return (int)Math.min(first+tot(s.substring(n/2,n),n/2,c+1),last+tot(s.substring(0,n/2),n/2,c+1));
        
        
     
        
    }
 
 
    public static void solve()
    {   
        int n=in.nextInt();
        in.nextLine();
        String s=in.nextLine();
        //char[] c = s.toCharArray();
        System.out.println(s);
        System.out.println(tot(s,n,'a'));
        
    }
    
	public static void main (String[] args)
	 {
	 int t=in.nextInt();
	 while(t-->0)
	 {
	  solve();
	 }
}
}