#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n == 1) {
      if (s[0] == 'a')
        cout << 0 << "\n";
      else
        cout << 1 << "\n";
      continue;
    }
    unordered_map<char, int> ma;
    for (int i = 0; i < n; i++) {
      ma[s[i]] += 1;
    }
    int mm = 'a' + (n == 2 ? 2 : n / 2);
    if (ma['a'] >= n / 2) {
      bool b = true;
      for (char c = 'a', d = 2; c < mm; c++, d *= 2) {
        if ((int)n / d == 0) {
          if (ma[c] != 1) b = false;
          break;
        }
        if (ma[c] != n / d) {
          b = false;
          break;
        }
      }
      if (b)
        cout << "0\n";
      else
        cout << n - ma['a'] << "\n";
      continue;
    }
    ma.clear();
    int moves = 0;
    string ss = s;
    for (char c = 'a', d = 2; c < mm; c++, d *= 2) {
      int c1 = 0, c2 = 0, m = n / d;
      for (int j = 0; j < n / d; j++) {
        if (ss[j] == c) c1++;
        if (ss[j + m] == c) c2++;
      }
      if (m == 0) {
        if (ss[0] == c) c1++;
        moves += abs(c1 - 1);
        break;
      }
      if (c1 > c2) {
        moves += abs(c1 - n / d);
        ss = ss.substr(n / d);
      } else {
        moves += abs(c2 - n / d);
        ss = ss.substr(0, n / d);
      }
    }
    cout << moves << "\n";
  }
}
