#include <bits/stdc++.h>
using namespace std;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {-1, 1, 0, 0};
int main() {
  long long t;
  scanf("%lld", &t);
  ;
  while (t--) {
    long long n;
    scanf("%lld", &n);
    string s;
    cin >> s;
    if (s.size() == 1) {
      if (s[0] == 'a')
        cout << 0 << endl;
      else
        cout << 1 << endl;
      continue;
    }
    long long size = log2(n + 1) + 1;
    vector<long long> vec[size];
    char c = 'a';
    long long ind = 0;
    for (int i = n / 2; i >= 1;) {
      long long cnt = 0;
      for (int j = 0; j < n; j++) {
        if (s[j] != c) cnt++;
        if ((j + 1) % i == 0) {
          vec[ind].push_back(cnt);
          cnt = 0;
        }
      }
      i /= 2;
      ind++;
      c++;
    }
    for (int i = 0; i < n; i++) {
      if (s[i] != c)
        vec[ind].push_back(1);
      else
        vec[ind].push_back(0);
    }
    for (int i = 1; i < size - 1; i++) {
      long long cnt = 1;
      for (int j = 0; j < vec[i].size(); j += 4) {
        vec[i][j] += vec[i - 1][cnt];
        vec[i][j + 1] += vec[i - 1][cnt];
        vec[i][j + 2] += vec[i - 1][cnt - 1];
        vec[i][j + 3] += vec[i - 1][cnt - 1];
        cnt += 2;
      }
    }
    long long res = LLONG_MAX;
    for (int i = 0; i < vec[size - 1].size(); i += 2) {
      vec[size - 1][i] += vec[size - 2][i + 1];
      vec[size - 1][i + 1] += vec[size - 2][i];
      res = min(res, vec[size - 1][i]);
      res = min(res, vec[size - 1][i + 1]);
    }
    cout << res << endl;
  }
  return 0;
}
