#include <bits/stdc++.h>
using namespace std;
long long int divide(char *s, long long int l, long long int r, char c) {
  if ((r - l + 1) == 1) {
    if (s[r] == c)
      return 0;
    else {
      return 1;
    }
  } else {
    long long int f1 = 0, f2 = 0;
    for (long long int i = l; i <= l + (r - l) / 2; i++) {
      if (s[i] == c) f1++;
    }
    for (long long int i = l + (r - l) / 2 + 1; i <= r; i++) {
      if (s[i] == c) f2++;
    }
    long long int sum = (r - l + 1) / 2 - max(f1, f2);
    long long int mid = l + (r - l) / 2;
    if (f1 > f2)
      sum += divide(s, mid + 1, r, (char)(c + 1));
    else if (f2 < f1)
      sum += divide(s, l, mid, (char)(c + 1));
    else {
      sum += min(divide(s, mid + 1, r, (char)(c + 1)),
                 divide(s, l, mid, (char)(c + 1)));
    }
    return sum;
  }
}
void SOLVE() {
  long long int n;
  cin >> n;
  char s[n + 5];
  cin >> s;
  long long int sum = divide(s, 0, n - 1, 'a');
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    SOLVE();
  }
  return 0;
}
