#include <bits/stdc++.h>
using namespace std;
int compute(string s, int l, int r, char c) {
  int i, lc = 0, rc = 0, k = 0, k1, k2;
  if (r - l == 1) return (s[l] != c) || (s[r] != c);
  int mid = (l + r) / 2;
  for (i = l; i < mid; i++) {
    if (s.at(i) == c) lc++;
    if (s.at(mid + (i - l)) == c) rc++;
  }
  k1 = ((r - l) / 2) - lc;
  k1 += compute(s, mid, r, c + 1);
  k2 = ((r - l) / 2) - rc;
  k2 += compute(s, l, mid, c + 1);
  k = min(k1, k2);
  return k;
}
int main() {
  int T, N, b;
  cin >> T;
  string s;
  while (T--) {
    cin >> N;
    cin >> s;
    b = compute(s, 0, N, 'a');
    cout << b << endl;
  }
  return 0;
}
