#include <bits/stdc++.h>
using namespace std;
string s;
int call(int a, int b, char ref) {
  int count = 0;
  for (int i = a; i < b; i++) {
    if (s[i] != ref) count++;
  }
  return count;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> s;
    int left = 0;
    int right = n;
    int ans = 0;
    char ref = 'a';
    while (true) {
      if (right - left == 1) {
        (s[left] == ref) ? (ans = ans) : (ans = ans + 1);
        break;
      }
      int mid = (left + right) / 2;
      int p = call(left, mid, ref);
      int q = call(mid, right, ref);
      ans = ans + min(p, q);
      if (p > q) {
        right = mid;
      } else {
        left = mid;
      }
      ref = ref + 1;
    }
    cout << ans << endl;
  }
}
