#include <bits/stdc++.h>
using namespace std;
long long n, m, k = 0, t, i, j, x, s = 0;
string s1;
const long long N = 5000100;
long long rec(long long n1, string s2, char ch) {
  if (n1 == 1) {
    if (s2[0] == ch)
      return 0;
    else
      return 1;
  }
  long long p = 0, q = 0;
  for (long long i = 0; i < n1 / 2; i++) {
    if (s2[i] != ch) p++;
  }
  for (long long i = n1 - 1; i >= n1 / 2; i--) {
    if (s2[i] != ch) q++;
  }
  return min(rec(n1 / 2, s2.substr(n1 / 2, n1 / 2), ch + 1) + p,
             rec(n1 / 2, s2.substr(0, n1 / 2), ch + 1) + q);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s1;
    cout << rec(n, s1, 'a') << "\n";
  }
}
