#include <bits/stdc++.h>
using namespace std;
long long int t, n;
string s;
long long int F(long long int start, long long int end, char c) {
  if (start >= end) {
    if (start == end && s[start] != c) {
      return 1;
    }
    return 0;
  }
  long long int x1 = 0, x2 = 0, length = end - start + 1, j = start;
  for (long long int i = 1; i <= length; i++) {
    if (s[j] != c) {
      if (i > length / 2) {
        x2++;
      } else {
        x1++;
      }
    }
    j++;
  }
  if (x1 < x2) {
    return x1 + F(start + length / 2, end, (char)(c + 1));
  } else if (x2 < x1) {
    return x2 + F(start, start + length / 2 - 1, (char)(c + 1));
  } else {
    return min(x1 + F(start + length / 2, end, (char)(c + 1)),
               x2 + F(start, start + length / 2 - 1, (char)(c + 1)));
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> s;
    s = "0" + s;
    cout << F(1, n, 'a');
    cout << "\n";
  }
  return 0;
}
