#include <bits/stdc++.h>
const int MAXN = 2e5 + 10;
const int mod = 998244353;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
using namespace std;
char s[MAXN];
long long ans, ans1;
void dfs1(long long l, long long r, char need, long long tot) {
  if (l > r)
    return;
  else if (l == r) {
    if (s[l] == need) {
      ans1 = min(ans1, tot);
      return;
    } else {
      ans1 = min(ans1, tot + 1);
      return;
    }
  }
  long long sum1 = 0, sum2 = 0;
  long long mid = (l + r) / 2;
  for (long long i = l; i <= mid; i++) {
    if (s[i] != need) sum1++;
  }
  for (long long i = mid + 1; i <= r; i++) {
    if (s[i] != need) sum2++;
  }
  dfs1(l, mid, need + 1, tot + sum2);
  dfs1(mid + 1, r, need + 1, tot + sum1);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n;
    ans1 = INF;
    ans = 0;
    scanf("%lld", &n);
    scanf("%s", s + 1);
    dfs1(1, n, 'a', 0);
    printf("%lld\n", ans1);
  }
  return 0;
}
