#include <bits/stdc++.h>
using namespace std;
int recursion(string s, int n, char tar, int ha) {
  if (s.length() == 1) {
    if (s[0] != tar) {
      return ha + 1;
    }
    return ha;
  }
  int cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != tar) {
      cnt1++;
    }
  }
  for (int i = n / 2; i < n; i++) {
    if (s[i] != tar) {
      cnt2++;
    }
  }
  return min(recursion(s.substr(n / 2, n / 2), n / 2, char(tar + 1), ha + cnt1),
             recursion(s.substr(0, n / 2), n / 2, char(tar + 1), ha + cnt2));
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  char tar = 'a';
  int curr = n / 2;
  int m = n / 2;
  cout << recursion(s, n, tar, 0) << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
