#include <bits/stdc++.h>
using namespace std;
long long fun(string s, long long n, char c) {
  if (n == 1) {
    if (s[0] != c)
      return 1;
    else
      return 0;
  }
  long long c1 = 0, c2 = 0;
  for (long long i = 0; i < n / 2; i++) {
    if (s[i] != c) c1++;
  }
  for (long long i = n / 2; i < n; i++) {
    if (s[i] != c) c2++;
  }
  long long a1 = fun(s.substr(0, n / 2), n / 2, char(c + 1)) + c2;
  long long a2 = fun(s.substr(n / 2, n / 2), n / 2, char(c + 1)) + c1;
  return min(a1, a2);
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = fun(s, s.length(), 'a');
  cout << ans << "\n";
}
int32_t main() {
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
