#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
char s[N];
int cnt = 0, ans = 0x3f3f3f3f;
int getgood(int k, int l, int r) {
  if (l + 1 == r) {
    if (s[l + 1] != 'a' + k) cnt++;
    ans = min(ans, cnt);
    cnt--;
  } else {
    int tmp = cnt;
    for (int i = l + 1; i <= (l + r) / 2; ++i) {
      if (s[i] != 'a' + k) cnt++;
    }
    getgood(k + 1, (l + r) / 2, r);
    cnt = tmp;
    tmp = cnt;
    for (int i = (l + r) / 2 + 1; i <= r; ++i) {
      if (s[i] != 'a' + k) cnt++;
    }
    getgood(k + 1, l, (l + r) / 2);
    cnt = tmp;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n >> s + 1;
    ans = 0x3f3f3f3f;
    getgood(0, 0, n);
    cout << ans << endl;
  }
  return 0;
}
