import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author xwchen
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int T = in.nextInt();
            while (T-- > 0) {
                int n = in.nextInt();
                char[] s = in.nextLine().toCharArray();
                out.println(getResult(s, 'a', 0, n - 1));
            }
        }

        int getResult(char[] s, char c, int left, int right) {
            if (left == right) {
                return s[left] == c ? 0 : 1;
            }
            int leftNeed = 0;
            int rightNeed = 0;
            int mid = (left + right) / 2;
            for (int i = left; i <= mid; ++i) {
                if (c != s[i]) {
                    ++leftNeed;
                }
            }
            for (int i = mid + 1; i <= right; ++i) {
                if (c != s[i]) {
                    ++rightNeed;
                }
            }
            char next = (char) (c + 1);
            return Math.min(leftNeed + getResult(s, next, mid + 1, right), rightNeed + getResult(s, next, left, mid));
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public InputReader(InputStream inputStream) {
            this.reader = new BufferedReader(
                    new InputStreamReader(inputStream));
        }

        public String next() {
            while (!tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String ret = "";
            try {
                ret = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

