#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  auto solve = [&]() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    function<int(int, int, char)> solve = [&](int l, int r, char c) {
      if (l == r) return s[l] == c ? 0 : 1;
      int m = (l + r) / 2;
      int A = 0, B = 0;
      for (int i = 0; i <= m; i++) A += s[i] != c;
      for (int i = m + 1; i <= r; i++) B += s[i] != c;
      return min(B + solve(l, m, c + 1), A + solve(m + 1, r, c + 1));
    };
    cout << solve(0, n - 1, 'a') << '\n';
  };
  int nT;
  for (cin >> nT; nT--;) solve();
  return 0;
}
