#include <bits/stdc++.h>
using namespace std;
const int nax = 1e7;
const int mod = 1e9 + 7;
long long int minstep(string s, char x) {
  if (s.length() == 1) {
    return !(s[0] == x);
  }
  long long int n = s.length();
  long long int hf1x = 0, hf2x = 0;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != x) {
      hf1x++;
    }
  }
  for (int i = (n / 2); i < n; i++) {
    if (s[i] != x) {
      hf2x++;
    }
  }
  string sub1 = s.substr(0, n / 2);
  string sub2 = s.substr(n / 2, n / 2);
  return min(hf1x + minstep(sub2, x + 1), hf2x + minstep(sub1, x + 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    string s;
    cin >> n;
    cin >> s;
    cout << minstep(s, 'a') << endl;
  }
}
