#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    long long int left = 0, right = 0;
    long long int answer = 0;
    long long int c = 0;
    long long int beg = 0, end = n - 1;
    while (beg <= end) {
      long long int left = 0, right = 0, mid = beg + (end - beg) / 2;
      map<char, long long int> l, r;
      for (long long int i = beg; i <= end; i++) {
        if (i <= mid)
          l[s[i]]++;
        else
          r[s[i]]++;
        if (s[i] == (char)('a' + c)) {
          if (i <= mid)
            left++;
          else
            right++;
        }
      }
      long long int len = (end - beg + 1) / 2;
      if (beg == end) len = 1;
      answer += (len - max(left, right));
      if (beg == end) break;
      if (left > right)
        beg = mid + 1;
      else if (right > left)
        end = mid;
      else {
        bool flag = false;
        for (char alpha = (char)(c + 1); alpha <= 'z'; alpha++) {
          if (l[alpha] > r[alpha]) {
            flag = true;
            break;
          }
        }
        if (!flag)
          end = mid;
        else
          beg = mid + 1;
      }
      c++;
    }
    cout << answer << "\n";
  }
  return 0;
}
