#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll solverec(string &s, char ch, ll le, ll re) {
  if (le == re) {
    return s[le] != ch;
  }
  ll len = re - le + 1, c = 0;
  for (int i = le; i < le + len / 2; i++) {
    if (s[i] != ch) c++;
  }
  ll op = c + solverec(s, ch + 1, le + len / 2, re);
  c = 0;
  for (int i = le + len / 2; i <= re; i++) {
    if (s[i] != ch) c++;
  }
  op = min(op, c + solverec(s, ch + 1, le, le + len / 2 - 1));
  return op;
}
void solve() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  cout << solverec(s, 'a', 0, n - 1) << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
