#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int cost(char c, string s, int n) {
  if (n == 1)
    if (c == s[0])
      return 0;
    else
      return 1;
  int c1 = 0, c2 = 0;
  string s1, s2;
  for (int i = 0; i < n / 2; i++) {
    s1.push_back(s[i]);
    if (s[i] != c) c1++;
  }
  for (int i = n / 2; i < n; i++) {
    s2.push_back(s[i]);
    if (s[i] != c) c2++;
  }
  return min(c2 + cost(c + 1, s1, n / 2), c1 + cost(c + 1, s2, n / 2));
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  cout << cost('a', s, n) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
