#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int ck(string& s, int i, int j, char c) {
  if (i == j) {
    if (s[i] == c)
      return 0;
    else
      return 1;
  }
  int mid = i + (j - i) / 2;
  int cnt = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0;
  for (int ii = i; ii <= mid; ii++) {
    if (s[ii] == c) cnt++;
    if (s[ii] == (c + 1)) cnt1++;
    if (s[ii - i + mid + 1] == c) cnt2++;
    if (s[ii - i + mid + 1] == (c + 1)) cnt3++;
  }
  int ans = 0, ans1 = 0;
  ans += (mid + 1 - i - cnt2);
  ans += ck(s, i, mid, c + 1);
  ans1 += (mid + 1 - i - cnt);
  ans1 += ck(s, mid + 1, j, c + 1);
  return min(ans, ans1);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << (ck(s, 0, n - 1, 'a')) << '\n';
  }
}
