#include <bits/stdc++.h>
using namespace std;
int func(map<pair<int, int>, vector<int> >& mp, char a, int begi, int endi) {
  if (begi == endi) return (mp[{begi, endi}][a - 'a'] == 0);
  int ans = 0;
  int midi = (begi + endi) / 2;
  char temp = a + 1;
  return +min((midi - begi + 1) - mp[{midi + 1, endi}][a - 'a'] +
                  func(mp, temp, begi, midi),
              (midi - begi + 1) - mp[{begi, midi}][a - 'a'] +
                  func(mp, temp, midi + 1, endi));
}
int main() {
  long long int test_case;
  cin >> test_case;
  while (test_case--) {
    long long int n;
    cin >> n;
    string str;
    cin >> str;
    if (n == 1)
      (str[0] == 'a') ? cout << "0" << endl : cout << "1" << endl;
    else {
      long long int i, j, t;
      long long int temp = n;
      int count1 = 0;
      while (temp != 1) count1 += 1, temp /= 2;
      map<pair<int, int>, vector<int> > mp;
      for (i = 0; i < count1; i++) {
        for (j = 0; j < str.length(); j += 0) {
          vector<int> vec1(26, 0);
          for (t = j; t < j + pow(2, i); t++) {
            vec1[str[t] - 'a'] += 1;
          }
          mp[{j, t - 1}] = vec1;
          j = t;
        }
      }
      cout << func(mp, 'a', 0, n - 1) << endl;
    }
  }
}
