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