#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, r, l, f, b, i, mid, step;
  char c[10000000];
  cin >> t;
  while (t--) {
    cin >> n;
    mid = n / 2;
    for (i = 0; i < n; i++) {
      cin >> c[i];
    }
    char a = 'a';
    l = 0;
    r = n;
    step = 0;
  label:
    if (l >= r) {
      goto label1;
    }
    f = 0;
    b = 0;
    for (i = l; i < mid; i++) {
      if (c[i] == a) {
        f++;
      }
    }
    for (i = mid; i < r; i++) {
      if (c[i] == a && i >= mid) {
        b++;
      }
    }
    if (f >= b) {
      step += mid - f;
      l = mid;
      a = a + 1;
      mid += mid / 2;
      goto label;
    } else {
      step += mid - b;
      r = mid;
      a = a + 1;
      mid = mid / 2;
      goto label;
    }
  label1:
    cout << step << "\n";
  }
  return 0;
}
