#include <bits/stdc++.h>
using namespace std;
bool check(vector<long long> &v, int m, int n) {
  int prev = -1;
  int l = m, r = n - 1;
  if (l > r) return false;
  while (r >= l) {
    if (v[r] > v[l]) {
      if (v[l] < prev) return false;
      prev = v[l];
      l++;
    } else {
      if (v[r] < prev) return false;
      prev = v[r];
      r--;
    }
  }
  return true;
}
int goods(string &s, char c, int l, int r) {
  if (r - l + 1 == 1) return (s[l] != c);
  int templ = 0, tempr = 0;
  for (int i = l; i <= l + (r - l) / 2; i++) templ += (s[i] != c);
  for (int i = l + (r - l) / 2 + 1; i <= r; i++) tempr += (s[i] != c);
  return min(
      templ + goods(s, (char)((((c - 'a') + 1) % 26) + 'a'),
                    l + (r - l) / 2 + 1, r),
      goods(s, (char)((((c - 'a') + 1) % 26) + 'a'), l, l + (r - l) / 2) +
          tempr);
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << goods(s, 'a', 0, n - 1) << endl;
  }
  return 0;
}
