#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
long long fac[1] = {1}, inv[1] = {1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mp(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return ret;
}
long long cmb(long long r, long long c) {
  return fac[r] * inv[c] % MOD * inv[r - c] % MOD;
}
char s[131073];
int psum[131073][26];
int gett(int l, int r, int c) {
  if (l == 0) return (r - l + 1) - psum[r][c];
  return (r - l + 1) - (psum[r][c] - psum[l - 1][c]);
}
int go(int l, int r, int c) {
  if (l == r) {
    return s[l] != c;
  }
  int mid = (l + r) / 2;
  int ls = gett(l, mid, c), rs = gett(mid + 1, r, c);
  ls += go(mid + 1, r, c + 1), rs += go(l, mid, c + 1);
  return min(ls, rs);
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    for (int i = 0; i < 26; i++) psum[0][i] = 0;
    for (int i = 0; i < n; i++) {
      s[i] -= 'a';
      if (i) {
        for (int j = 0; j < 26; j++) psum[i][j] = psum[i - 1][j];
      }
      psum[i][s[i]]++;
    }
    printf("%d\n", go(0, n - 1, 0));
  }
}
