#include <bits/stdc++.h>
using namespace std;
char ss[111111];
int t, n;
int x(char c, int l, int r) {
  int cnt = 0;
  for (int i = l; i < r; i++) {
    if (ss[i] != c) cnt++;
  }
  return cnt;
}
int s(char c, int l, int r) {
  if (l == r) return (ss[l] != c);
  int len = (r - l + 1) / 2;
  return (min(x(c, l, l + len - 1) + s(c + 1, l + len, r),
              x(c, l + len, r) + s(c + 1, l, l + len - 1)));
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%s", &n, ss);
    printf("%d\n", s('a', 0, n - 1));
  }
  return 0;
}
