#include <bits/stdc++.h>
using namespace std;
int func(string &str, int s, int e, char c) {
  if (s == e) {
    if (str[s] == c)
      return 0;
    else
      return 1;
  }
  int mid = (s + e) / 2;
  int l = 0, r = 0;
  for (int i = s; i <= mid; i++)
    if (str[i] != c) l++;
  for (int i = mid + 1; i <= e; i++)
    if (str[i] != c) r++;
  return min(l + func(str, mid + 1, e, c + 1), r + func(str, s, mid, c + 1));
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string str;
    cin >> str;
    int i = 0, j = n - 1;
    cout << func(str, 0, n - 1, 'a') << endl;
  }
  return 0;
}
