#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a <= b)
    return a;
  else
    return b;
}
long long minstr(string &s, char c, long long n) {
  long long min_moves1 = 0, min_moves2 = 0, min_moves = 0;
  if (n == 1) {
    if (s[0] == c)
      return 0;
    else
      return 1;
  }
  string s1 = s.substr(0, n / 2);
  string s2 = s.substr(n / 2, n / 2);
  for (long long i = 0; i < n / 2; i++) {
    if (s1[i] != c) min_moves1++;
    if (s2[i] != c) min_moves2++;
  }
  c++;
  min_moves +=
      min(min_moves1 + minstr(s2, c, n / 2), min_moves2 + minstr(s1, c, n / 2));
  return min_moves;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    char c = 'a';
    if (n == 1) {
      if (s[0] == 'a')
        cout << 0 << '\n';
      else
        cout << 1 << '\n';
      continue;
    }
    long long min_moves = minstr(s, c, n);
    cout << min_moves << '\n';
  }
}
