#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int t, n;
string s;
int solve(int l, int r, char dem) {
  if (l >= r) {
    if (s[l] != dem)
      return 1;
    else
      return 0;
  }
  int mid = (r + l) / 2, sum1 = 0, sum2 = 0;
  for (int i = l; i <= mid; ++i)
    if (s[i] != dem) sum1++;
  for (int i = mid + 1; i <= r; ++i)
    if (s[i] != dem) sum2++;
  return min(sum2 + solve(l, mid, char(dem + 1)),
             sum1 + solve(mid + 1, r, char(dem + 1)));
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s;
    cout << solve(0, s.length() - 1, 'a') << endl;
  }
}
