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