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