#include <bits/stdc++.h>
using namespace std;
long long gs(string s, long long n, char c) {
  long long ans = 0;
  if (n == 1) {
    if (s[0] != c) {
      return 1;
    } else
      return 0;
  }
  long long h1 = 0, h2 = 0;
  for (long long i = 0; i < n / 2; i++)
    if (s[i] == c) h1++;
  for (long long i = n / 2; i < n; i++)
    if (s[i] == c) h2++;
  if (h1 > h2) {
    ans += n / 2 - h1;
    c++;
    s = s.substr(n / 2, n);
    n = n / 2;
    ans += gs(s, n, c);
  } else if (h2 > h1) {
    ans += n / 2 - h2;
    c++;
    s = s.substr(0, n / 2);
    n = n / 2;
    ans += gs(s, n, c);
  } else {
    c++;
    long long h11 = 0, h21 = 0;
    for (long long i = 0; i < n / 2; i++)
      if (s[i] == c) h11++;
    for (long long i = n / 2; i < n; i++)
      if (s[i] == c) h21++;
    if (h21 > h11) {
      ans += n / 2 - h1;
      s = s.substr(n / 2, n);
      n = n / 2;
      ans += gs(s, n, c);
    } else {
      ans += n / 2 - h2;
      s = s.substr(0, n / 2);
      n = n / 2;
      ans += gs(s, n, c);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    if (n == 1) {
      if (s[0] != 'a')
        cout << "1" << endl;
      else
        cout << "0" << endl;
      continue;
    }
    char c = 'a';
    long long ans = gs(s, n, c);
    cout << ans << endl;
  }
  return 0;
}
