#include <bits/stdc++.h>
using namespace std;
int solve(string s, char c) {
  int n = s.size(), one = 0, two = 0;
  string s1, s2;
  if (s.size() == 1) {
    if (s[0] == c)
      return 0;
    else
      return 1;
  }
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != c) one++;
    s1 += s[i];
  }
  for (int i = n / 2; i < s.size(); i++) {
    if (s[i] != c) two++;
    s2 += s[i];
  }
  return min(solve(s1, c + 1) + two, solve(s2, c + 1) + one);
}
int32_t main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << solve(s, 'a') << "\n";
  }
  return 0;
}
