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