#include <bits/stdc++.h>
using namespace std;
int solve(string& s, int low, int high, int good) {
  if (high == low) {
    if (s[low] == 'a' + good) {
      return 0;
    } else {
      return 1;
    }
  }
  int mid = (low + high) / 2;
  int left = solve(s, low, mid, good + 1);
  int right = solve(s, mid + 1, high, good + 1);
  int l = 0, r = 0;
  for (int i = low; i <= mid; i++) {
    if (s[i] != 'a' + good) {
      l++;
    }
  }
  for (int i = mid + 1; i <= high; i++) {
    if (s[i] != 'a' + good) {
      r++;
    }
  }
  return min(l + right, r + left);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    cout << solve(s, 0, n - 1, 0) << '\n';
  }
  return 0;
}
