#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long mod = 1e9 + 7;
const long long big = 1e18;
const double PI = 2 * asin(1);
int N;
string S;
int solve(int from, int to, char c) {
  if (to - from == 1) {
    if (S[from] == c)
      return 0;
    else
      return 1;
  }
  int numf = 0, numb = 0;
  for (int i = from; i < to; ++i) {
    if (S[i] != c) {
      if (i - from < to - i)
        numf++;
      else
        numb++;
    }
  }
  char next = c + 1;
  if (next > 'z') next = 'a';
  return min(numb + solve(from, (from + to) / 2, next),
             numf + solve((from + to) / 2, to, next));
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> N >> S;
    cout << solve(0, N, 'a') << endl;
  }
}
