#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int solve(string second, char c, int len) {
  if (len == 1) {
    if (second[0] == c)
      return 0;
    else
      return 1;
  }
  int r1 = 0, r2 = 0;
  for (int i = 0; i < len / 2; i++)
    if (second[i] != c) r1++;
  for (int i = len / 2; i < len; i++)
    if (second[i] != c) r2++;
  if (r2 < r1)
    return r2 + solve(second.substr(0, len / 2), c + 1, len / 2);
  else if (r1 < r2)
    return r1 + solve(second.substr(len / 2, len / 2), c + 1, len / 2);
  else
    return r1 + min(solve(second.substr(len / 2, len / 2), c + 1, len / 2),
                    solve(second.substr(0, len / 2), c + 1, len / 2));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    string second;
    cin >> second;
    cout << solve(second, 'a', n) << '\n';
  }
  exit(0);
}
