#include <bits/stdc++.h>
using namespace std;
int cal(string s, int st, int n, char c) {
  int a = (n - st) / 2;
  if (n - st == 1 & s[st] != c) return 1;
  if (a <= 0) return 0;
  int t1 = 0, t2 = 0;
  for (int i = st; i < st + a; i++) {
    if (s[i] != c) t1++;
  }
  for (int i = n - 1; i >= n - a; i--) {
    if (s[i] != c) t2++;
  }
  if (t1 < t2)
    return cal(s, st + a, n, c + 1) + t1;
  else if (t1 == t2)
    return min(cal(s, st + a, n, c + 1) + t1, cal(s, st, n - a, c + 1) + t2);
  else
    return cal(s, st, n - a, c + 1) + t2;
}
int hack() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = cal(s, 0, n, 'a');
  cout << ans << endl;
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) hack();
  return 0;
}
