#include <bits/stdc++.h>
using namespace std;
char a[200010];
int s(int l, int r, char ch) {
  if (l >= r) {
    if (a[l] == ch)
      return 0;
    else
      return 1;
  }
  int mid;
  mid = (l + r) / 2;
  int num1 = mid - l + 1;
  int num2 = num1;
  for (int i = l; i <= mid; i++) {
    if (a[i] == ch) num1--;
  }
  for (int i = mid + 1; i <= r; i++) {
    if (a[i] == ch) num2--;
  }
  return min(s(l, mid, ch + 1) + num2, s(mid + 1, r, ch + 1) + num1);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    scanf(" %s", a);
    printf("%d\n", s(0, n - 1, 'a'));
  }
  return 0;
}
