#include <bits/stdc++.h>
using namespace std;
int main() {
  cout.setf(ios::fixed), cout.precision(0);
  srand((unsigned)time(NULL));
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    char c = 'a';
    int l = 0, r = n;
    while (n) {
      if (n == 1) {
        if (s[l] != c) {
          ans++;
        }
        break;
      }
      long long cl = 0, cr = 0;
      int lc = 0, rc = 0;
      for (int i = l; i < l + (r - l) / 2; ++i) {
        cl += s[i] - 'a';
        if (s[i] == c) lc++;
      }
      for (int i = l + (r - l) / 2; i < r; ++i) {
        cr += s[i] - 'a';
        if (s[i] == c) rc++;
      }
      if (lc > rc) {
        ans += max(0, n / 2 - lc);
        l = l + (r - l) / 2;
      } else if (lc < rc) {
        ans += max(0, n / 2 - rc);
        r = l + (r - l) / 2;
      } else {
        if (cl <= cr) {
          ans += max(0, n / 2 - rc);
          r = l + (r - l) / 2;
        } else {
          ans += max(0, n / 2 - lc);
          l = l + (r - l) / 2;
        }
      }
      c++;
      n /= 2;
    }
    cout << ans << "\n";
  }
}
