#include <bits/stdc++.h>
using namespace std;
string s;
int binary(char ch, int l, int h) {
  int mid = (l + h) / 2;
  int cntl = 0, cnth = 0;
  if (l + 1 == h) {
    if (ch != s[l])
      return 1;
    else
      return 0;
  }
  for (int i = l; i < mid; ++i)
    if (ch == s[i]) ++cntl;
  for (int i = mid; i < h; ++i)
    if (ch == s[i]) ++cnth;
  if (cntl < cnth) {
    return (mid - l - cnth) + binary(ch + 1, l, mid);
  } else if (cntl > cnth) {
    return (mid - l - cntl) + binary(ch + 1, mid, h);
  } else {
    return (mid - l - cntl) +
           min(binary(ch + 1, l, mid), binary(ch + 1, mid, h));
  }
}
void solve() {
  int n;
  cin >> n;
  cin >> s;
  int l = 0, h = n;
  int ans = 0;
  char ch = 'a';
  cout << binary(ch, 0, n) << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int ___T;
  cin >> ___T;
  while (___T--) solve();
  cout << flush;
}
