import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
//import net.leksi.cf.SegTreeEx1;

public class D {

    public static void main(String[] args) throws IOException {
        new D().run();
    }

    private void load_inputs(final BufferedReader br) throws IOException {
        try (PrintWriter pw = select_output();) {
            int t = Integer.valueOf(br.readLine().trim());
            while(t-- > 0) {
                int n = Integer.valueOf(br.readLine().trim());
                String s = br.readLine().trim();
                solve(n, s, pw);
            }
        }
    }
    
    private void solve(final int n, final String s, final PrintWriter pw) {
        pw.println(calc(s, 'a'));
    }

    private long calc(String s, char c) {
        if(s.length() == 1) {
            return s.charAt(0) == c ? 0 : 1;
        }
        String left = s.substring(0, s.length() >> 1);
        String right = s.substring(s.length() >> 1);
        long n_left = Arrays.stream(left.split("")).filter(v -> v.charAt(0) != c).count();
        long n_right = Arrays.stream(right.split("")).filter(v -> v.charAt(0) != c).count();
        return Math.min(n_right + calc(left, (char)((int)c + 1)), n_left  + calc(right, (char)((int)c + 1)));
    }
    
    String nameIn = getClass().getSimpleName().substring(0, 1) + ".in";
    String nameOut = null;

    private void run() throws IOException {
        File input = null;
        if (nameIn != null && (input = new File(nameIn)).exists()) {
            try (
                    FileReader fr = new FileReader(input);
                    BufferedReader br = new BufferedReader(fr);) {
                load_inputs(br);
            }
        } else {
            try (
                    InputStreamReader fr = new InputStreamReader(System.in);
                    BufferedReader br = new BufferedReader(fr);) {
                load_inputs(br);
            }
        }
    }

    PrintWriter select_output() throws FileNotFoundException {
        if (nameOut != null) {
            return new PrintWriter(nameOut);
        }
        return new PrintWriter(System.out);
    }

}
