#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string a;
    cin >> a;
    long long int l = 0, r = n - 1, ans = 0;
    if (n == 1) {
      if (a[0] == 'a')
        cout << 0 << endl;
      else
        cout << 1 << endl;
      continue;
    }
    char c = 'a';
    while (l < r) {
      long long int cnt = 0, cnt1 = 0;
      for (long long int i = l; i < ((r + l) + 1) / 2; i++) {
        if (a[i] == c) cnt++;
      }
      for (long long int i = ((r + l) + 1) / 2; i <= r; i++) {
        if (a[i] == c) cnt1++;
      }
      if (r == l + 1) {
        if ((a[l] == c && a[r] == c + 1) || (a[l] == c + 1 && a[r] == c))
          break;
        else if ((a[l] == c || a[l] == c + 1) || (a[r] == c || a[r] == c + 1)) {
          ans++;
          break;
        } else {
          ans += 2;
          break;
        }
      }
      ans += ((r - l) + 1) / 2 - max(cnt, cnt1);
      c = c + 1;
      if (max(cnt, cnt1) == cnt) {
        l = (((r + l) + 1) / 2);
      } else {
        r = (((r + l) + 1) / 2) - 1;
      }
    }
    cout << ans << endl;
  }
}
