#include <bits/stdc++.h>
using namespace std;
long long dp[131073][27];
string s;
long long fxn(long long low, long long high, long long ch) {
  if (low == high) {
    if (s[low] - 'a' == ch)
      return 0;
    else
      return 1;
  }
  long long mid = low + (high - low) / 2;
  long long pos1, pos2;
  long long do1 = 0, do2 = 0;
  for (long long i = low; i <= mid; i++) {
    if (s[i] != ch + 'a') do1++;
  }
  for (long long i = mid + 1; i <= high; i++) {
    if (s[i] != ch + 'a') do2++;
  }
  pos1 = do1 + fxn(mid + 1, high, ch + 1);
  pos2 = do2 + fxn(low, mid, ch + 1);
  return min(pos1, pos2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    cin >> s;
    long long i, j;
    long long ans = fxn(0, n - 1, 0);
    cout << ans << endl;
  }
}
