#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
string str;
int getCost(int l, int r, char ch) {
  int cost = 0;
  for (int i = l; i <= r; i++) {
    if (str[i] != ch) cost++;
  }
  return cost;
}
int solve(int l, int r, char ch) {
  if (l == r) {
    if (str[l] == ch) return 0;
    return 1;
  }
  int mid = (l + r) / 2;
  return min(getCost(l, mid, ch) + solve(mid + 1, r, (char)(ch + 1)),
             getCost(mid + 1, r, ch) + solve(l, mid, (char)(ch + 1)));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> str;
    cout << solve(0, n - 1, 'a') << "\n";
  }
}
