#include <bits/stdc++.h>
using namespace std;
int findans(string s, char c) {
  if (s.size() == 1) {
    if (s[0] == c)
      return 0;
    else
      return 1;
  }
  string s1 = s.substr(0, s.size() / 2);
  string s2 = s.substr(s.size() / 2, s.size() / 2);
  int a1 = findans(s2, c + 1);
  for (char &d : s1) {
    if (d != c) ++a1;
  }
  int a2 = findans(s1, c + 1);
  for (char &d : s2) {
    if (d != c) ++a2;
  }
  return min(a1, a2);
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << findans(s, 'a') << endl;
  }
  return 0;
}
