#include <bits/stdc++.h>
using namespace std;
int ans;
void process(string str, char a, int s, int e) {
  int cnt1 = 0, cnt2 = 0, ncnt1 = 0, ncnt2 = 0;
  if (s > e) return;
  for (int i = s; i <= (s + e) / 2; i++) {
    if (str[i] != a) cnt1++;
    if (str[i] != a + 1) ncnt1++;
  }
  for (int i = (s + e) / 2 + 1; i <= e; i++) {
    if (str[i] != a) cnt2++;
    if (str[i] != a + 1) ncnt2++;
  }
  if (cnt1 > cnt2) {
    ans += cnt2;
    if (s == e) {
      ans += cnt1;
      return;
    }
    if (cnt1 != 0) process(str, a + 1, s, (s + e) / 2);
  } else if (cnt1 < cnt2) {
    ans += cnt1;
    if (s == e) {
      ans += cnt2;
      return;
    }
    if (cnt2 != 0) process(str, a + 1, (s + e) / 2 + 1, e);
  } else {
    ans += cnt1;
    if (ncnt1 > ncnt2) {
      process(str, a + 1, (s + e) / 2 + 1, e);
    } else {
      process(str, a + 1, s, (s + e) / 2);
    }
  }
}
int main() {
  cin.tie(nullptr);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    string str;
    ans = 0;
    cin >> n >> str;
    process(str, 'a', 0, n - 1);
    cout << ans << '\n';
  }
  return 0;
}
