#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
string s;
long long solve(long long l, long long r, char curr) {
  if (l == r) {
    return (s[l] != curr);
  }
  long long m = (l + r) / 2;
  long long lcost = solve(m + 1, r, curr + 1);
  long long rcost = solve(l, m, curr + 1);
  for (int i = l; i <= m; i++) {
    if (s[i] != curr) {
      lcost++;
    }
  }
  for (int i = m + 1; i <= r; i++) {
    if (s[i] != curr) {
      rcost++;
    }
  }
  return min(lcost, rcost);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    cin >> s;
    cout << solve(0, n - 1, 'a') << "\n";
  }
}
