#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n > 0) {
    int a;
    cin >> a;
    vector<char> m(a);
    for (int i = 0; i < a; i++) {
      cin >> m[i];
    }
    int coun = 0;
    char ant = 'a';
    if (a == 1) {
      if (m[0] == 'a') {
        cout << 0 << endl;
      } else {
        cout << 1 << endl;
      }
    } else {
      while (true) {
        if (count(m.begin(), m.end(), ant) != 0) {
          while (a > 0) {
            int pos = find(m.begin(), m.end(), ant) - m.begin();
            if (pos < a / 2) {
              for (int i = 0; i < a / 2; i++) {
                if (m[i] != ant) {
                  coun++;
                }
              }
              m.erase(m.begin(), m.begin() + a / 2);
            } else {
              for (int i = a / 2; i < a; i++) {
                if (m[i] != ant) {
                  coun++;
                }
              }
              m.erase(m.begin() + a / 2, m.begin() + a);
            }
            ant++;
            a = a / 2;
          }
          break;
        } else {
          ant++;
        }
      }
      cout << coun << endl;
    }
    n--;
  }
  return 0;
}
