#include <bits/stdc++.h>
using namespace std;
int t, n;
string s1;
int solve(int l, int r, char c) {
  if (l == r) return s1[l] != c;
  ;
  int mid = l + (r - l) / 2;
  int cntl, cntr;
  cntl = 0, cntr = 0;
  for (int i = l; i <= mid; i++) {
    cntl += s1[i] != c;
  }
  for (int i = mid + 1; i <= r; i++) {
    cntr += s1[i] != c;
  }
  return min(cntl + solve(mid + 1, r, c + 1), cntr + solve(l, mid, c + 1));
}
int main() {
  ios::sync_with_stdio(0);
  int ans;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s1;
    ans = solve(0, n - 1, 'a');
    cout << ans << endl;
  }
}
