#include <bits/stdc++.h>
using namespace std;
bool is_prime(int n) {
  int root = sqrt(n);
  if (n == 1) return false;
  for (int i = 2; i <= root; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int digitsOfFact(int n) {
  double x = 0;
  for (int i = 1; i <= n; i++) {
    x += log10(i);
  }
  int res = x + 1 + 1e-9;
  return res;
}
const long long inf = 1e17 * 3;
const int MAXN = 2e5 + 5;
char s[MAXN];
int calc(int l, int r, char c) {
  if (l == r) {
    if (s[l] == c)
      return 0;
    else
      return 1;
  }
  int cnt1 = 0, cnt2 = 0, m;
  m = (l + r) / 2;
  for (int i = l; i <= m; i++)
    if (s[i] != c) cnt1++;
  for (int i = (m + 1); i <= r; i++)
    if (s[i] != c) cnt2++;
  long long x = cnt1 + calc(m + 1, r, c + 1);
  long long y = cnt2 + calc(l, m, c + 1);
  return min(x, y);
}
int accept() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  cout << calc(1, n, 'a') << "\n";
  return 0;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    accept();
  }
  return 0;
}
