#include <bits/stdc++.h>
using namespace std;
string s;
long long int divide(long long int l, long long int r, char ch) {
  if (l == r) {
    if (s[l] == ch) {
      return 0;
    } else {
      return 1;
    }
  }
  long long int mid = (l + r) / 2;
  long long int lc = 0, rc = 0;
  for (long long int i = l; i <= mid; i++) {
    if (s[i] != ch) {
      lc++;
    }
  }
  for (long long int i = mid + 1; i <= r; i++) {
    if (s[i] != ch) {
      rc++;
    }
  }
  return min(lc + divide(mid + 1, r, ch + 1), rc + divide(l, mid, ch + 1));
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    cin >> s;
    cout << divide(0, n - 1, 'a') << '\n';
  }
  return 0;
}
