#include <bits/stdc++.h>
using namespace std;
const long long IM = 1e15 + 37;
const long long M = 1e9 + 7;
const long long N = 2e6 + 10;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long x = 0;
    long long l = 0, r = n - 1;
    long long ans = 0;
    char c = 'a';
    while (l <= r) {
      x = l + (r - l) / 2;
      if (l == r) {
        if (s[l] != c) ans++;
        break;
      }
      long long z = 0, k = 0;
      for (long long i = l; i <= x; i++) {
        if (s[i] != c) z++;
      }
      for (long long i = x + 1; i <= r; i++) {
        if (s[i] != c) k++;
      }
      ans += min(z, k);
      if (z <= k) {
        l = x + 1;
      } else {
        r = x;
      }
      c++;
    }
    cout << ans << "\n";
  }
  return 0;
}
