#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, m, t;
char a[maxn];
int get(int l, int r, int pos) {
  int cnt1 = 0, cnt2 = 0;
  int mid = (l + r) / 2;
  char p = 'a' - 1 + pos;
  if (l == r) {
    if (a[l] == p)
      return 0;
    else
      return 1;
  }
  for (int i = l; i <= mid; i++)
    if (a[i] != p) cnt1++;
  for (int i = mid + 1; i <= r; i++)
    if (a[i] != p) cnt2++;
  if (cnt1 < cnt2) {
    return cnt1 + get(mid + 1, r, pos + 1);
  } else if (cnt1 == cnt2) {
    return min(cnt2 + get(l, mid, pos + 1), cnt1 + get(mid + 1, r, pos + 1));
  } else {
    return cnt2 + get(l, mid, pos + 1);
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%s", a + 1);
    printf("%d\n", get(1, n, 1));
  }
  return 0;
}
