#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double error = 2e-6;
const long double PI = acosl(-1);
inline long long int MOD(long long int x, long long int m = mod) {
  long long int y = x % m;
  return (y >= 0) ? y : y + m;
}
const int inf = 1e9;
const long long int infl = 1061109567;
const int nmax = 1000 + 10;
string ss;
int DP(int start, int finish, char let) {
  if (start == finish) {
    if (ss[start - 1] == let)
      return 0;
    else
      return 1;
  }
  int t1 = start, t2 = (start + finish) / 2, t3 = t2 + 1, t4 = finish;
  int cnt = t4 - t3 + 1 - count(ss.begin() + t3 - 1, ss.begin() + t4, let) +
            DP(t1, t2, let + 1);
  int cntt = t2 - t1 + 1 - count(ss.begin() + t1 - 1, ss.begin() + t2, let) +
             DP(t3, t4, let + 1);
  return min(cnt, cntt);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> ss;
    int i;
    if (n == 1 && ss == "a") {
      cout << 0 << endl;
      continue;
    }
    if (n == 1) {
      cout << 1 << endl;
      continue;
    }
    cout << DP(1, n, 'a') << endl;
  }
  return 0;
}
