#include <bits/stdc++.h>
using namespace std;
long long right(string s, long long n, char c) {
  long long cnt = 0;
  for (long long i = 0; i < n / 2; i++)
    if (s[i] == c) cnt++;
  return cnt;
}
long long left(string s, long long n, char c) {
  long long cnt = 0;
  for (long long i = n / 2; i < n; i++)
    if (s[i] == c) cnt++;
  return cnt;
}
long long good(string s, long long n, char c) {
  long long ans = 0;
  if (n == 1) {
    if (s[0] == c)
      return 0;
    else
      return 1;
  } else {
    long long h1 = 0, h2 = 0;
    h1 = right(s, n, c);
    h2 = left(s, n, c);
    h1 = n / 2 - h1;
    h2 = n / 2 - h2;
    string m = s;
    string s1 = s.substr(0, n / 2);
    string s2 = m.substr(n / 2, n);
    c++;
    n = n / 2;
    ans += min(h1 + good(s2, n, c), h2 + good(s1, 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;
    char c = 'a';
    long long ans = 0;
    ans += good(s, n, c);
    cout << ans << endl;
  }
  return 0;
}
