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

public class rough 
{
    public static void main(String[] args) 
    {
        FastReader scn = new FastReader();
        int t = scn.nextInt();

        while(t>0)
        {
            int n = scn.nextInt();
            String s = scn.nextLine();
        
            int k = helper(n); // n = 2^k
            int totaldiffleters = k+1;

            int ans=0;

            char ch = 'a';
            int helper1 = n/2;
            int a=0;
            for(int i=1; i<=k-2; i++)
            {
                ans = ans + func(s.substring(a,helper1), ch);

                a = helper1;
                helper1 = helper1/2;
                ch++;
            }


            

            System.out.println(ans);
            t--;
        }
    }

    public static int func(String s, char q)
    {
        int n = s.length();


        int helper1 = n/2;
        if(helper1 == 0) helper1 = 1;

        int idx1 = 0;
        int count = 0;
        char ch = q;
        int i=1;
        while(idx1 < s.length())
        {

            if(s.charAt(idx1) != ch) count++;

            i++;
            idx1++;

            if(i > helper1)
            {
                helper1 = helper1/2;
                i=1;
                ch++;

                if(helper1 == 0) helper1=1;
            }     
        }



        int helper2 = n/2;
        if(helper2 == 0) helper2 = 1;

        int idx2 = s.length()-1;
        int count2 = 0;
        char ch2 = q;
        int i2=1;
        while(0<=idx2)
        {

            if(s.charAt(idx2) != ch2) count2++;

            i2++;
            idx2--;

            if(i2 > helper2)
            {
                helper2 = helper2/2;
                i2=1;
                ch2++;

                if(helper2 == 0) helper2=1;
            }     
        }

        return Math.min(count, count2);

    }

    public static int helper(int n)
    {
        int ans = 0;
        while(n%2 == 0)
        {
            n = n/2;
            ans++;
        }
        return ans;
    }
    
    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; 
        } 
    } 
}