#include <bits/stdc++.h>
int t, n;
char str[300000];
int a[1000000];
int lg[1000000];
int dp(int l, int r, int ly) {
  if (l == r) {
    return a[l] != ly;
  }
  int mid = (l + r) / 2;
  int suml(0), sumr(0);
  for (int i = l; i <= mid; ++i) {
    if (a[i] != ly) ++suml;
  }
  for (int i = mid + 1; i <= r; ++i) {
    if (a[i] != ly) ++sumr;
  }
  int ansl, ansr;
  ansl = dp(l, mid, ly + 1);
  ansr = dp(mid + 1, r, ly + 1);
  return std::min(ansl + sumr, ansr + suml);
}
void work(void) {
  scanf("%d", &n);
  scanf("%s", str + 1);
  for (int i = 1; i <= n; ++i) {
    a[i] = str[i] - 'a';
  }
  printf("%d\n", dp(1, n, 0));
  return;
}
int main() {
  lg[0] = lg[1] = 0;
  for (int i = 2; i <= 132000; ++i) lg[i] = lg[i / 2] + 1;
  scanf("%d", &t);
  while (t--) {
    work();
  }
  return 0;
}
