#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1), eps = 1e-9;
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
const int N = 3e5 + 5, mod = 1e9 + 7, inf = 1e9;
const long long INF = 1e18 + 7;
long long ans;
void calc(string s, char a, long long sum) {
  if ((int)s.size() == 1) {
    if (s[0] != a) sum++;
    ans = min(ans, sum);
    return;
  }
  string left = s.substr(0, (int)s.size() / 2);
  string rigth = s.substr((int)s.size() / 2, (int)s.size() / 2);
  long long l = 0, r = 0;
  for (char c : left)
    if (c != a) l++;
  for (char c : rigth)
    if (c != a) r++;
  calc(left, a + 1, sum + r);
  calc(rigth, a + 1, sum + l);
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  ans = INF;
  calc(s, 'a', 0ll);
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  cin >> T;
  while (T--) solve();
}
