#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long ksm(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 2e5 + 10;
int n;
char s[N];
int solve(int l, int len, int step) {
  if (len == 1) return s[l] != 'a' + step;
  int cnt1 = 0, cnt2 = 0;
  for (int i = l; i <= l + len / 2 - 1; i++) {
    if (s[i] != 'a' + step) {
      cnt1++;
    }
  }
  for (int i = l + len / 2; i <= l + len - 1; i++) {
    if (s[i] != 'a' + step) {
      cnt2++;
    }
  }
  return min(cnt2 + solve(l, len / 2, step + 1),
             cnt1 + solve(l + len / 2, len / 2, step + 1));
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    scanf("%s", s + 1);
    if (n == 1) {
      printf("%d\n", s[0] != 'a');
      continue;
    }
    int ans = solve(1, n, 0);
    printf("%d\n", ans);
  }
  return 0;
}
