import java.util.*;
import java.util.stream.*;
import java.io.*;
import java.math.*;

public class Main { 
    
    static boolean FROM_FILE = false;
    
    static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;

    static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader() { 
            if (FROM_FILE) {
                try {
                    br = new BufferedReader(new FileReader("input.txt")); 
                } catch (IOException error) {
                }   
            } else {
                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; 
        } 
    }
    static int max(int... nums) {
        int res = Integer.MIN_VALUE;
        for (int num: nums) res = Math.max(res, num);
        return res;
    }
    static int min(int... nums) {
        int res = Integer.MAX_VALUE;
        for (int num: nums) res = Math.min(res, num);
        return res;
    }
    static long max(long... nums) {
        long res = Long.MIN_VALUE;
        for (long num: nums) res = Math.max(res, num);
        return res;
    }
    static long min(long... nums) {
        long res = Long.MAX_VALUE;
        for (long num: nums) res = Math.min(res, num);
        return res;
    }
    
    static FastReader fr = new FastReader();
    static PrintWriter out;
    
    public static void main(String[] args) { 
        if (FROM_FILE) {
            try {
                out = new PrintWriter(new FileWriter("output.txt"));
            } catch (IOException error) {
                
            }
        } else {
            out = new PrintWriter(new OutputStreamWriter(System.out));
        }
        new Main().run();
        out.flush();
        out.close();
    } 
    
    int needMoves(char[] str, int a, int b, char c) {
        int len = (b - a + 1);
        if (len == 1) return str[a] == c ? 0 : 1;
        int mid = a + len / 2 - 1;
        int cnt1 = 0;
        for (int i = a; i <= mid; i += 1) {
            if (str[i] != c) cnt1 += 1;
        }
        cnt1 += needMoves(str, mid + 1, b, (char)(c + 1));
        int cnt2 = 0;
        for (int i = mid + 1; i <= b; i += 1) {
            if (str[i] != c) cnt2 += 1;
        }
        cnt2 += needMoves(str, a, mid, (char)(c + 1));
        return min(cnt1, cnt2);
    }
    
    void run() {
        int t = fr.nextInt();
        while (t-- > 0) {
            int n = fr.nextInt();
            char[] str = fr.nextLine().toCharArray();
            int step = needMoves(str, 0, n - 1, 'a');
            out.println(step);
        }
    }
}