#include <bits/stdc++.h>
using namespace std;
int min_cost(const string& s, int left, int right, char c) {
  if (left + 1 == right) {
    return s[left] != c;
  }
  int mid = (left + right) / 2;
  int cntl = 0;
  for (int i = left; i < mid; ++i) {
    cntl += s[i] != c;
  }
  int cntr = 0;
  for (int i = mid; i < right; ++i) {
    cntr += s[i] != c;
  }
  return min(cntl + min_cost(s, mid, right, c + 1),
             cntr + min_cost(s, left, mid, c + 1));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << min_cost(s, 0, n, 'a') << "\n";
  }
  return 0;
}
