#include <bits/stdc++.h>
using namespace std;
int fun1(string s, int n, int i, int j, char c) {
  if (i == j) {
    if (s[i] == c)
      return 0;
    else
      return 1;
  }
  int x = 0, y = 0, temp1, temp2;
  for (int k = i; k <= (i + j) / 2; k++) {
    if (s[k] != c) x++;
  }
  for (int k = ((i + j) / 2) + 1; k <= j; k++) {
    if (s[k] != c) y++;
  }
  if (x < y)
    return x + fun1(s, n, ((i + j) / 2) + 1, j, c + 1);
  else
    return y + fun1(s, n, i, (i + j) / 2, c + 1);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    cout << fun1(s, n, 0, n - 1, 'a') << endl;
  }
  return 0;
}
