import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Solution1385D {
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Solver1385D solver = new Solver1385D();
    int n = in.nextInt();
    for (int i = 0; i < n; i++) {
      solver.solve(i, in, out);
    }
    out.close();
  }

  static class Solver1385D {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int len = in.nextInt();
      String s = in.next();
      Map<Integer, Map<Integer, Map<Character, Integer>>> cache = new HashMap<>();
      Map<Integer, Map<Integer, Map<Character, Integer>>> diffCache = new HashMap<>();

      Set<Character> chars = new HashSet<>();

      out.println(minChange(s, 0, len, 'a', cache, diffCache));
    }

    private int minChange(String s, int start, int len, char c,
        Map<Integer, Map<Integer, Map<Character, Integer>>> cache,
        Map<Integer, Map<Integer, Map<Character, Integer>>> diffCache) {
      if (len == 1) {
        if (s.charAt(start) == c) {
          return 0;
        }
        return 1;
      }

      if (cache.containsKey(start) && cache.get(start).containsKey(len)
          && cache.get(start).get(len).containsKey(c)) {
        return cache.get(start).get(len).get(c);
      }

      if (!cache.containsKey(start)) {
        cache.put(start, new HashMap<>());
      }

      Map<Integer, Map<Character, Integer>> startMap = cache.get(start);
      Map<Character, Integer> charMap = startMap.get(len);
      if (charMap == null) {
        charMap = new HashMap<>();
        startMap.put(len, charMap);
      }


      int result = charDiff(s, start, len / 2, c, diffCache)
          + minChange(s, start + len / 2, len / 2, (char)(c+1), cache, diffCache);

      int tmp = charDiff(s, start + len / 2, len / 2, c, diffCache);

      if (tmp < result) {
        result = Math.min(result,
            tmp + minChange(s, start, len / 2, (char)(c+1), cache, diffCache));
      }

      charMap.put(c, result);

      return result;
    }

    private int charDiff(String s, int start, int len, char c,
        Map<Integer, Map<Integer, Map<Character, Integer>>> cache) {
      if (cache.containsKey(start) && cache.get(start).containsKey(len)
          && cache.get(start).get(len).containsKey(c)) {
        return cache.get(start).get(len).get(c);
      }

      if (!cache.containsKey(start)) {
        cache.put(start, new HashMap<>());
      }

      Map<Integer, Map<Character, Integer>> startMap = cache.get(start);
      Map<Character, Integer> charMap = startMap.get(len);
      if (charMap == null) {
        charMap = new HashMap<>();
        startMap.put(len, charMap);
      }

      int result = 0;

      for (int i = start; i < start + len; i++) {
        if (s.charAt(i) != c) {
          result++;
        }
      }
      charMap.put(c, result);

      return result;
    }
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 262144);
      tokenizer = null;
    }

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

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