#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int inf = 2e9;
const long long linf = 2e18;
using namespace std;
const int maxn = 2e6 + 5;
char a[maxn];
int v[26];
int dfs(int l, int r, int now) {
  if (l == r) return a[l] != now;
  int numl = 0, numr = 0;
  int mid = (l + r) >> 1;
  memset(v, 0, sizeof(v));
  for (int i = l; mid >= i; i++) {
    v[a[i]]++;
  }
  numl = v[now];
  memset(v, 0, sizeof(v));
  for (int i = mid + 1; r >= i; i++) {
    v[a[i]]++;
  }
  numr = v[now];
  return min(dfs(l, mid, now + 1) + (r - l + 1) / 2 - numr,
             dfs(mid + 1, r, now + 1) + (r - l + 1) / 2 - numl);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    scanf("%s", a + 1);
    for (int i = 1; n >= i; i++) a[i] -= 'a';
    printf("%d\n", dfs(1, n, 0));
  }
  return 0;
}
