#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    int num, d = 0, sum = 0, k;
    cin >> num;
    string s;
    cin >> s;
    char *a = &s[0];
    k = num;
    while (k > 1) {
      multiset<char> m(a, a + k / 2);
      multiset<char> n(a + k / 2, a + k);
      if (m.count('a' + d) == k / 2) {
        s = s.substr(k / 2, k);
      } else if (n.count('a' + d) == k / 2) {
        s = s.substr(0, k / 2);
      } else if ((n.count('a' + d) == 0 && m.count('a' + d) == 0) ||
                 n.count('a' + d) == m.count('a' + d)) {
        int u, l = 0, up = (log(num) / log(2));
        for (u = d + 1; u <= up; u++) {
          if (n.count('a' + u) > m.count('a' + u)) {
            s = s.substr(k / 2);
            sum = sum - m.count('a' + d) + k / 2;
            l = 1;
            break;
          } else if (n.count('a' + u) < m.count('a' + u)) {
            sum = sum - n.count('a' + d) + k / 2;
            s = s.substr(0, k / 2);
            l = 1;
            break;
          }
        }
        if (l == 0) {
          s = s.substr(k / 2);
          sum = sum - n.count('a' + d) + k / 2;
        }
      } else if (m.count('a' + d) > n.count('a' + d)) {
        sum = sum - m.count('a' + d) + (k) / 2;
        s = s.substr(k / 2);
      } else {
        sum = sum - n.count('a' + d) + (k) / 2;
        s = s.substr(0, k / 2);
      }
      k = k / 2;
      d++;
      a = &s[0];
    }
    if (a[0] != 'a' + d) sum++;
    cout << sum << "\n";
  }
}
