#include <bits/stdc++.h>
using namespace std;
long long calc(int l, int r, const string& s, char c) {
  if (l + 1 == r) return s[l] == c ? 0 : 1;
  int mid = l + (r - l) / 2;
  long long cntl = (r - l) / 2 - count(s.begin() + l, s.begin() + mid, c) +
                   calc(mid, r, s, c + 1);
  long long cntr = (r - l) / 2 - count(s.begin() + mid, s.begin() + r, c) +
                   calc(l, mid, s, c + 1);
  return min(cntl, cntr);
}
int main() {
  int t, n;
  string s;
  cin >> t;
  for (int q = 0; q < t; ++q) {
    cin >> n;
    cin >> s;
    cout << calc(0, n, s, 'a') << '\n';
  }
  return 0;
}
