#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  string s;
  cin >> n;
  vector<long long> pr(n + 1, 0);
  vector<bool> v(n + 1, 0);
  long long fn = n;
  n /= 2;
  cin >> s;
  if (n == 0) {
    cout << (s[0] != 'a') << "\n";
    return;
  }
  s = s[0] + s;
  long long ans = 0;
  long long i;
  for (i = 0; n > 0; i++) {
    i %= 26;
    long long temp = 1e10;
    fill(pr.begin(), pr.end(), 0);
    for (long long j = 1; s[j]; j++) {
      if (s[j] != ('a' + i))
        pr[j] = pr[j - 1] + 1;
      else
        pr[j] = pr[j - 1];
    }
    long long sj = 1;
    for (long long j = n; j <= fn; j += n) {
      if (temp > pr[j] - pr[j - n] && !v[j] && !v[j - n + 1]) {
        sj = j - n + 1;
        temp = pr[j] - pr[j - n];
      }
    }
    for (long long j = sj; j < sj + n; j++) {
      s[j] = 'a' + i;
      v[j] = 1;
    }
    n /= 2;
    ans += temp;
  }
  bool flag = 1;
  for (long long j = 1; s[j]; j++) {
    if (s[j] == (char)('a' + i)) flag = 0;
  }
  ans += flag;
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
