#include <bits/stdc++.h>
using namespace std;
char s[131100];
int cal(int l, int r, char t) {
  int cnt = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] != t) cnt++;
  }
  return cnt;
}
int dfs(int l, int r, char t) {
  if (l == r) return cal(l, r, t);
  int ret = 1e9;
  int mid = (l + r) >> 1;
  ret = min(ret, dfs(l, mid, t + 1) + cal(mid + 1, r, t));
  ret = min(ret, dfs(mid + 1, r, t + 1) + cal(l, mid, t));
  return ret;
}
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    char temp = 'a';
    printf("%d\n", dfs(0, n - 1, temp));
  }
  return 0;
}
