#include <bits/stdc++.h>
const int INF = 1e9 + 7;
using namespace std;
int T, n;
string str;
int dp[20][20][131073];
int go(int pow, int s, char c) {
  if (dp[pow][c - 'a'][s] > -1) return dp[pow][c - 'a'][s];
  if (pow == 0) return dp[pow][c - 'a'][s] = str[s] == c ? 0 : 1;
  int c1 = 0, c2 = 0, len = (1 << pow - 1);
  for (int i = s; i < s + len; i++) {
    if (str[i] != c) c1++;
  }
  for (int i = s + len; i < s + len * 2; i++) {
    if (str[i] != c) c2++;
  }
  return dp[pow][c - 'a'][s] =
             min(c1 + go(pow - 1, s + len, c + 1), c2 + go(pow - 1, s, c + 1));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> T;
  while (T--) {
    cin >> n >> str;
    for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 20; j++) {
        for (int k = 0; k < n; k++) {
          dp[i][j][k] = -1;
        }
      }
    }
    if (n == 1) {
      if (str[0] == 'a')
        cout << 0 << "\n";
      else
        cout << 1 << "\n";
      continue;
    }
    int pow = 0, nn = 1;
    while (nn < n) {
      pow++;
      nn *= 2;
    }
    cout << go(pow, 0, 'a') << "\n";
  }
  return 0;
}
