#include <bits/stdc++.h>
using namespace std;
int solve(string s, char c, int l, int r, int step) {
  if (l >= r) {
    if (s[l] == c)
      return 0;
    else
      return 1;
  }
  int mi = (l + r) / 2;
  int left = 0;
  for (int i = l; i <= mi; i++) {
    if (s[i] != c) left += 1;
  }
  int right = 0;
  for (int i = mi + 1; i <= r; i++) {
    if (s[i] != c) right += 1;
  }
  if (left < right) {
    return left + solve(s, c + 1, mi + 1, r, step);
  } else {
    return right + solve(s, c + 1, l, mi, step);
    ;
  }
}
void generateInput() {
  int N = 1024;
  srand(time(NULL));
  cout << 1 << endl;
  cout << N << endl;
  for (int i = 0; i < N; i++) {
    char c = rand() % 26 + 'a';
    cout << c;
  }
}
int main() {
  int T;
  string s;
  int n;
  cin >> T;
  while (T--) {
    cin >> n >> s;
    cout << solve(s, 'a', 0, n - 1, 0) << endl;
  }
  return 0;
}
