#include <bits/stdc++.h>
using namespace std;
const int MAXN = 131075;
string a;
int count(int l, int r, char stat) {
  if (l > r) return 0;
  if (l == r) {
    return a[l] == stat ? 0 : 1;
  }
  int mid = (l + r) >> 1;
  int cntl = 0, cntr = 0;
  int ans = 0;
  for (int i = l; i <= mid; i++) {
    if (a[i] == stat) cntl++;
  }
  for (int i = mid + 1; i <= r; i++) {
    if (a[i] == stat) cntr++;
  }
  if (cntl >= cntr) {
    ans += (mid - l + 1) - cntl;
    ans += count(mid + 1, r, stat + 1);
  } else {
    ans += (r - mid) - cntr;
    ans += count(l, mid, stat + 1);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> a;
    if (n == 1) {
      if (a[0] != 'a') {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    } else
      cout << count(0, n - 1, 'a') << endl;
  }
  return 0;
}
