#include <bits/stdc++.h>
using namespace std;
string s;
long long count(long long l, long long r, char a) {
  long long cnt = 0;
  for (long long i = l; i < r; i++)
    if (s[i] == a) cnt++;
  return cnt;
}
long long solve(long long l, long long r, char a) {
  if (r - l == 1) {
    if (s[l] != a)
      return 1;
    else
      return 0;
  }
  long long cnt1, cnt2, mid = (l + r) / 2;
  cnt1 = ((r - l) / 2) - count(l, mid, a) + solve(mid, r, a + 1);
  cnt2 = ((r - l) / 2) - count(mid, r, a) + solve(l, mid, a + 1);
  return min(cnt1, cnt2);
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n >> s;
    long long ans = solve(0, n, 'a');
    cout << ans << '\n';
  }
  return 0;
}
