#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int solve(int l, int r, char m) {
  if (l == r) {
    if (s[l] == m)
      return 0;
    else
      return 1;
  }
  int mid = (l + r) >> 1, left = 0, right = 0, len = r - l + 1;
  for (int i = l; i <= mid; i++)
    if (s[i] == m) left++;
  for (int i = mid + 1; i <= r; i++)
    if (s[i] == m) right++;
  int ans = min(len / 2 - left + solve(mid + 1, r, m + 1),
                len / 2 - right + solve(l, mid, m + 1));
  return ans;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  char m = 'a';
  while (T--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> s[i];
    int ans = solve(1, n, m);
    cout << ans << endl;
  }
  return 0;
}
