#include <bits/stdc++.h>
using namespace std;
int countChar(string s, char ch) {
  int cnt = 0;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] != ch) cnt++;
  }
  return cnt;
}
int findTotalMoves(string s, int n, char ch) {
  if (n == 1) {
    if (s[0] == ch)
      return 0;
    else
      return 1;
  }
  int n1 = n / 2;
  string s1 = s.substr(0, n1);
  string s2 = s.substr(n1);
  int cnt1 = countChar(s1, ch);
  int cnt2 = countChar(s2, ch);
  if (cnt1 == 0 || cnt1 < cnt2) {
    return cnt1 + findTotalMoves(s2, n1, ch + 1);
  } else if (cnt2 == 0 || cnt2 < cnt1) {
    return cnt2 + findTotalMoves(s1, n1, ch + 1);
  } else {
    int res1 = cnt1 + findTotalMoves(s2, n1, ch + 1);
    int res2 = findTotalMoves(s1, n1, ch + 1) + cnt2;
    return min(res1, res2);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << findTotalMoves(s, n, 'a') << endl;
  }
  return 0;
}
