#include <bits/stdc++.h>
using namespace std;
string s;
long long int count(long long int l, long long int r, char c) {
  long long int i, ans = 0;
  for (i = l; i <= r; i++) {
    if (s[i] != c) ans++;
  }
  return ans;
}
long long int calc(long long int l, long long int r, char c) {
  if (r == l) {
    if (s[l] != c)
      return 1;
    else
      return 0;
  }
  long long int m = l + (r - l) / 2;
  long long int cl, cr;
  cl = count(l, m, c) + calc(m + 1, r, c + 1);
  cr = count(m + 1, r, c) + calc(l, m, c + 1);
  return min(cl, cr);
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    cin >> s;
    cout << calc(0, n - 1, 'a') << endl;
  }
}
