#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int good(string s, char c) {
  int n = s.size();
  if (n == 1) {
    return s[0] != c;
  }
  string s1 = s.substr(n / 2), s2 = s.substr(0, n / 2);
  int x = good(s1, c + 1) + n / 2 - count(s2.begin(), s2.end(), c);
  int y = good(s2, c + 1) + n / 2 - count(s1.begin(), s1.end(), c);
  return min(x, y);
}
void solve() {
  int n, m = 0, i = 0, j = 0, l, r, k = 0, x, y, z;
  cin >> n;
  string s;
  cin >> s;
  cout << good(s, 'a') << "\n";
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
