#include <bits/stdc++.h>
using namespace std;
const int N = 131082;
int t, n, cum[N][26];
char A[N];
string s;
void _clear() {}
int calc(int l, int r, int c) {
  if (l == 0) return cum[r][c];
  return cum[r][c] - cum[l - 1][c];
}
int fact(int l, int r, int c) {
  if (l == r) return (c != s[l] - 'a');
  int half = (r - l + 1) / 2;
  int ret = min(fact(l, r - half, c + 1) + half - calc(l + half, r, c),
                fact(l + half, r, c + 1) + half - calc(l, r - half, c));
  return ret;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    _clear();
    scanf("%d%s", &n, &A);
    s = A;
    for (int i = 0; i < 26; i++) cum[0][i] = 0;
    cum[0][s[0] - 'a'] = 1;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 26; j++) cum[i][j] = cum[i - 1][j];
      cum[i][s[i] - 'a']++;
    }
    printf("%d\n", fact(0, n - 1, 0));
  }
}
