#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;
}
int solve(string a, int n) {
  if (a.size() == 1) {
    if (a[0] == n + 'a') {
      return 0;
    } else {
      return 1;
    }
  }
  int a1 = 0, a2 = 0;
  int m = a.size();
  for (int i = 0; i < m; i++) {
    if ((i < m / 2) && a[i] == n + 'a') {
      a1++;
    } else if ((i >= m / 2) && a[i] == n + 'a') {
      a2++;
    }
  }
  return min((m / 2) - a1 + solve(a.substr(m / 2, a.size() / 2), n + 1),
             (m / 2) - a2 + solve(a.substr(0, a.size() / 2), n + 1));
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a;
    cin >> a;
    cout << solve(a, 0) << endl;
  }
  return 0;
}
