#include <bits/stdc++.h>
using namespace std;
bool DEBUG = 0;
string s;
long long n;
long long pre[200005][26];
long long func(long long l, long long r, char c) {
  if (l == r) {
    if (s[l] == c)
      return 0;
    else
      return 1;
  }
  long long le = r - l + 1;
  le /= 2;
  long long nr = l + ((r - l) / 2);
  long long nl = nr + 1;
  long long ans =
      (le - (pre[r + 1][c - 'a'] - pre[nl][c - 'a'])) + func(l, nr, c + 1);
  ans = min(ans, (le - (pre[nr + 1][c - 'a'] - pre[l][c - 'a'])) +
                     func(nl, r, c + 1));
  return ans;
}
void solve() {
  cin >> n;
  cin >> s;
  for (__typeof(26) j = (0) - ((0) > (26)); j != (26) - ((0) > (26));
       j += 1 - 2 * ((0) > (26)))
    pre[0][j] = 0;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    for (__typeof(26) j = (0) - ((0) > (26)); j != (26) - ((0) > (26));
         j += 1 - 2 * ((0) > (26))) {
      pre[i + 1][j] = pre[i][j];
    }
    pre[i + 1][s[i] - 'a']++;
  }
  cout << func(0, n - 1, 'a') << "\n";
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
