#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> arr(n);
    int k = int(log2(n));
    for (int i = 0; i < n; ++i) {
      if (s[i] != ('a' + k)) ++arr[i];
    }
    for (int i = k; i >= 0; --i) {
      char c = 'a' + i;
      int jump = pow(2, k - i);
      for (int j = 0; j < n; j = j + jump) {
        int cnt1 = 0;
        int cnt2 = 0;
        int sj = jump / 2;
        for (int k = j; k < j + sj; ++k) {
          if (s[k] != c) cnt1++;
        }
        for (int k = j + sj; k < j + jump; ++k) {
          if (s[k] != c) cnt2++;
        }
        arr[j] = min(cnt1 + arr[j + sj], cnt2 + arr[j]);
      }
    }
    cout << arr[0] << endl;
  }
  return 0;
}
