#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    long long int l = 0, r = n - 1, i, ans = 0;
    char c = 'a';
    while (l < r) {
      long long int m = l + (r - l) / 2;
      long long int s1 = 0, s2 = 0;
      for (i = l; i <= m; i++) {
        if (s[i] != c) s1++;
      }
      for (i = m + 1; i <= r; i++) {
        if (s[i] != c) s2++;
      }
      if (s1 <= s2) {
        ans += s1;
        for (i = l; i <= m; i++) {
          s[i] = c;
        }
        l = m + 1;
      } else {
        ans += s2;
        for (i = m + 1; i <= r; i++) {
          s[i] = c;
        }
        r = m;
      }
      c++;
    }
    if (s[l] != c) {
      ans++;
      s[l] = c;
    }
    cout << ans << endl;
  }
}
