#include <bits/stdc++.h>
#pragma GCC optize("02")
using namespace std;
using ll = long long;
const ll maxn = 2e5 + 5, inf = 1e18 + 18;
ll t, n;
string s1;
ll mn(string s, char c) {
  if (s.size() == 1) {
    if (s[0] == c)
      return 0;
    else
      return 1;
  }
  string s2 = "", s3 = "";
  ll n1 = 0, n2 = 0;
  for (ll i = 0; i < s.size() / 2; i++) {
    s2 += s[i];
    if (s[i] != c) n1++;
  }
  for (ll i = s.size() / 2; i < s.size(); i++) {
    s3 += s[i];
    if (s[i] != c) n2++;
  }
  return min(n1 + mn(s3, c + 1), n2 + mn(s2, c + 1));
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> s1;
    cout << mn(s1, 'a') << endl;
  }
}
