#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long f(string s, long long n) {
  if (n == 1) {
    if (s[0] == 'a')
      return 0;
    else
      return 1;
  } else {
    long long k = 0, l = 0;
    for (long long i = 0; i < n / 2; ++i) {
      if (s[i] != 'a') {
        ++k;
      }
    }
    for (long long i = n / 2; i < n; ++i) {
      if (s[i] != 'a') {
        ++l;
      }
    }
    string s1, s2;
    for (long long i = 0; i < n; ++i) {
      if (i < n / 2)
        s1.push_back(s[i] - 1);
      else
        s2.push_back(s[i] - 1);
    }
    return min(k + f(s2, n / 2), l + f(s1, n / 2));
  }
}
int main() {
  int t;
  while (cin >> t) {
    for (int i = 0; i < t; ++i) {
      long long n;
      cin >> n;
      string s;
      cin >> s;
      cout << f(s, n) << endl;
    }
  }
}
