#include <bits/stdc++.h>
using namespace std;
int all_char(char ch, string s) {
  int count = 0;
  for (char c : s)
    if (c != ch) ++count;
  return count;
}
int solve(char ch, string s) {
  int n = s.length();
  if (n == 0) return 0;
  if (n == 1) {
    if (s[0] == ch) return 0;
    return 1;
  }
  if (n == 2) {
    if (s[1] == s[0]) {
      if (s[0] == ch) return 0;
      return 2;
    }
    if ((s[0] == ch && s[0] == ch + 1) || (s[1] == ch && s[0] == ch + 1))
      return 0;
    if (s[0] == ch || s[1] == ch || s[0] == ch + 1 || s[1] == ch + 1) return 1;
    return 2;
  }
  return min(
      {(solve(ch + 1, s.substr(0, n / 2)) + all_char(ch, s.substr(n / 2))),
       (all_char(ch, s.substr(0, n / 2)) + solve(ch + 1, s.substr(n / 2)))});
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    string s;
    cin >> n;
    cin >> s;
    cout << solve('a', s) << endl;
  }
}
