#include <bits/stdc++.h>
using namespace std;
long long n, m, k = 0, t, i, j, x, s = 0;
string s1;
const long long N = 5000100;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s1;
    long long k2 = n - 1, k1 = 0, k3 = 0;
    long long c = 0, d = 0;
    char ch = 'a';
    while (n > 0) {
      n /= 2;
      c = 0, d = 0;
      for (i = k1; i < k1 + n; i++) {
        if (s1[i] == ch) c++;
      }
      for (j = k2; j >= n + k1; j--) {
        if (s1[j] == ch) d++;
      }
      if (d > c)
        k2 -= n;
      else
        k1 += n;
      ch++;
      k3 += n - max(c, d);
    }
    if (s1[k1] != ch) k3++;
    cout << k3 << "\n";
  }
}
