#include <bits/stdc++.h>
using namespace std;
int func(string &s, int l, int r, char a) {
  if ((r - l + 1) == 1) {
    if (s[l] == a) return 0;
    return 1;
  }
  int mid = l + (r - l) / 2;
  int f1 = 0;
  int f2 = 0;
  for (int i = l; i <= mid; i++) {
    if (s[i] != a) f1++;
  }
  for (int i = mid + 1; i <= r; i++) {
    if (s[i] != a) f2++;
  }
  return min(f1 + func(s, mid + 1, r, a + 1), f2 + func(s, l, mid, a + 1));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << func(s, 0, n - 1, 'a') << "\n";
  }
  return 0;
}
