#include <bits/stdc++.h>
using namespace std;
string s;
long long int solve(long long int start, long long int end, char ch) {
  if (end - start == 0) {
    if (s.at(start) != ch)
      return 1;
    else
      return 0;
  }
  long long int a = (long long int)(end - start + 1) / 2;
  long long int count1 = 0, count2 = 0, i;
  for (i = start; i < start + a; i++) {
    if (s.at(i) != ch) count1++;
  }
  for (i = start + a; i <= end; i++) {
    if (s.at(i) != ch) count2++;
  }
  ch++;
  return min(count1 + solve(start + a, end, ch),
             count2 + solve(start, start + a - 1, ch));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T, p;
  cin >> T;
  for (p = 1; p <= T; p++) {
    long long int N;
    cin >> N;
    cin >> s;
    long long int a = 0;
    a = solve(0, N - 1, 'a');
    cout << a << "\n";
  }
  return 0;
}
