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

public class D {
    static FastReader f = new FastReader();

    public static void main(String[] args) {
        int t = f.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    static String s;
    static void solve() {
        int n = f.nextInt();
        s = f.next();
        int[] occ = new int[26];
        int num = n/2;
        int i = 0;
        while (num != 0) {
            occ[i++] = num;
            num >>= 1;
        }
        occ[i] = num;
        int ans = rek(0,0,n,'a');
        System.out.println(ans);
    }

    static int rek(int ans, int left, int right, char c) {
        if(left+1 == right) {
            ans += s.charAt(left) == c ? 0 : 1;
            return ans;
        }

        int lftCnt = 0;
        for(int i=left;i<(left+right)/2;i++) {
            if(s.charAt(i) == c) {
                lftCnt++;
            }
        }

        int rightCnt = 0;
        for(int i=(left+right)/2;i<right;i++) {
            if(s.charAt(i) == c) {
                rightCnt++;
            }
        }

        //System.out.println(lftCnt+" "+rightCnt);

        c = (char) (c+1);

        if(lftCnt > rightCnt) {
            ans += (right-left)/2 - lftCnt;
            //System.out.println(ans);
            return rek(ans,(left+right)/2,right,c);
        } else if(lftCnt < rightCnt) {
            ans += (right-left)/2 -rightCnt;
            //System.out.println(ans);
            return rek(ans, left,(left+right)/2,c);
        }

        return Math.min(rek(ans + (right-left)/2 - lftCnt,(left+right)/2,right,c), rek(ans + (right-left)/2 -rightCnt,left,(left+right)/2,c) );
    }







    //fast input reader
    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;
        }
    }
}