#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    s = '.' + s;
    long long val = 'a';
    long long sz = n;
    long long first = 0, second = 0, ans = 0;
    long long start = 1, end = n;
    while (sz != 0) {
      if (sz == 1) {
        if (s[start] != val) {
          ans++;
        }
        break;
      }
      for (int i = start; i < start + sz / 2; i++) {
        long long x = s[i];
        if (x == val) {
          first++;
        }
      }
      for (int i = start + sz / 2; i <= end; i++) {
        long long x = s[i];
        if (x == val) {
          second++;
        }
      }
      if (first >= second) {
        ans += sz / 2 - first;
        start += sz / 2;
      } else if (second > first) {
        ans += sz / 2 - second;
        end -= sz / 2;
      }
      sz /= 2;
      val++;
      first = 0, second = 0;
    }
    cout << ans << "\n";
    cout << "\n";
  }
}
