#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, a[N];
void work();
signed main() {
  long long g;
  cin >> g;
  while (g--) work();
}
string s;
inline long long calc(long long l, long long r, char c) {
  long long tot_left = 0;
  long long tot_right = 0;
  if (l == r) {
    return s[l] != c;
  }
  long long mid = l + r >> 1;
  for (long long i = l; i <= mid; ++i) tot_left += (s[i] != c);
  for (long long i = mid + 1; i <= r; ++i) tot_right += (s[i] != c);
  return min(tot_left + calc(mid + 1, r, c + 1),
             tot_right + calc(l, mid, c + 1));
}
void work() {
  cin >> n;
  cin >> s;
  cout << calc(0, n - 1, 'a') << endl;
}
