#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    char arr[n + 1];
    for (int i = 1; i <= n; i++) cin >> arr[i];
    long long int l = 1;
    long long int r = n;
    long long int ans = 0;
    for (int i = 0; i < 26; i++) {
      char ch = 97 + i;
      long long int cnt1 = 0;
      long long int cnt2 = 0;
      long long int w = 0;
      for (int i = l; i < l + (-l + r + 1) / 2; i++) {
        if (arr[i] == ch) cnt1++;
      }
      for (int i = r; i > r - (r - l + 1) / 2; i--) {
        if (arr[i] == ch) cnt2++;
      }
      long long int k1, k2;
      ans += min((r - l + 1) / 2 - cnt1, (r - l + 1) / 2 - cnt2);
      if (cnt1 >= cnt2) {
        l = (l + (r - l + 1) / 2);
      } else {
        r = (r - (r - l + 1) / 2);
      }
      if (l == r) {
        ch++;
        if (arr[l] != ch) ans++;
        break;
      }
    }
    cout << ans << endl;
  }
}
