#include <bits/stdc++.h>
using namespace std;
int n, m, t, k;
int fz(string a, char c, int len) {
  if (len == 1) return a[0] != c;
  string l = a.substr(0, len / 2);
  string r = a.substr(len / 2);
  return min(fz(l, c + 1, len / 2) + len / 2 - count(r.begin(), r.end(), c),
             fz(r, c + 1, len / 2) + len / 2 - count(l.begin(), l.end(), c));
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    string a;
    cin >> a;
    int ans = fz(a, 'a', a.length());
    cout << ans << endl;
  }
  return 0;
}
