#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18;
const long long int mod = 1e9 + 9;
long long int fun(long long int s, long long int e, char ch, string &s1) {
  if (s == e) {
    if (s1[s] == ch) return 0;
    return 1;
  }
  int nn = (e - s + 1) / 2;
  int a1 = 0;
  for (int i = 0; i < nn; i++) {
    if (s1[s + i] != ch) a1++;
  }
  a1 += fun(s + nn, e, (ch + 1), s1);
  int a2 = 0;
  for (int i = 0; i < nn; i++) {
    if (s1[e - i] != ch) a2++;
  }
  a2 += fun(s, s + nn - 1, (ch + 1), s1);
  return min(a1, a2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int a, b, c, d, e, f, g, p, r, n, k, m, t, q, x, z, y;
  t = 1;
  cin >> t;
  string s1, s2, s3, s4, s5;
  s3 = "abacaba";
  m = s3.size();
  for (int t0 = 1; t0 <= t; t0++) {
    cin >> n >> s1;
    c = fun(0, n - 1, 'a', s1);
    cout << c << "\n";
  }
  return 0;
}
