#include <bits/stdc++.h>
using namespace std;
int n;
int make_good(char* str, char good, int i, int j) {
  if (i + 1 == j) {
    return str[i] == good ? 0 : 1;
  }
  int fhc = 0;
  int shc = 0;
  int size = j - i;
  int l = i;
  for (; l < j - size / 2; ++l) {
    fhc += (str[l] == good);
    shc += (str[l + size / 2] == good);
  }
  int mgf = size / 2 - fhc + make_good(str, good + 1, i + size / 2, j);
  int mgs = size / 2 - shc + make_good(str, good + 1, i, i + size / 2);
  return min(mgf, mgs);
}
void solve() {
  scanf("%d", &n);
  char str[n + 1];
  scanf("%s", &str);
  int res = make_good(str, 'a', 0, n);
  printf("%d\n", res);
}
int main() {
  int TC;
  scanf("%d", &TC);
  while (TC--) solve();
  return 0;
}
