#include <bits/stdc++.h>
using namespace std;
const int Inf = 1e9;
char s[131075];
int n, m, dp[131075][35], sum[131075][35];
int ls(int x) { return x << 1; }
int rs(int x) { return x << 1 | 1; }
void DP(int p, int l, int r) {
  if (l == r) {
    sum[p][s[l] - 'a' + 1] = 1;
    for (int i = 1; i <= 26; i++) dp[p][i] = 1;
    dp[p][s[l] - 'a' + 1] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  DP(ls(p), l, mid);
  DP(rs(p), mid + 1, r);
  int Llen = mid - l + 1, Rlen = r - mid;
  for (int i = 1; i <= 26; i++) {
    sum[p][i] = sum[ls(p)][i] + sum[rs(p)][i];
    if (i == 26)
      dp[p][i] = Inf;
    else
      dp[p][i] = min(Llen - sum[ls(p)][i] + dp[rs(p)][i + 1],
                     Rlen - sum[rs(p)][i] + dp[ls(p)][i + 1]);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    memset(dp, Inf, sizeof dp);
    memset(sum, 0, sizeof sum);
    scanf("%d", &n);
    scanf("%s", s + 1);
    DP(1, 1, n);
    printf("%lld\n", dp[1][1]);
  }
  return 0;
}
