#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
char s[N];
int getgood(int k, int l, int r) {
  if (l + 1 == r)
    return s[l + 1] != 'a' + k;
  else {
    int cnt = 0, ccnt = 0;
    for (int i = l + 1; i <= (l + r) / 2; ++i)
      if (s[i] != 'a' + k) cnt++;
    for (int i = (l + r) / 2 + 1; i <= r; ++i)
      if (s[i] != 'a' + k) ccnt++;
    return min(getgood(k + 1, l, (l + r) / 2) + ccnt,
               getgood(k + 1, (l + r) / 2, r) + cnt);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n >> s + 1;
    cout << getgood(0, 0, n) << endl;
  }
  return 0;
}
