#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const double PI = 3.141592653589793238460;
const int INF = 1e9 + 5;
long long power(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  while (y) {
    if (y & 1) res = ((res % mod) * (x % mod)) % mod;
    y >>= 1;
    x = ((x % mod) * (x % mod)) % mod;
  }
  return res;
}
string s;
int count(int l, int r, char c) {
  int res = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] == c) res++;
  }
  return res;
}
int recur(int l, int r, char c, int *ans) {
  if (l == r) {
    if (s[l] == c) return 0;
    return 1;
  }
  int mid = (l + r) / 2;
  return min((mid - l + 1 - count(l, mid, c)) + recur(mid + 1, r, c + 1, ans),
             ((r - mid) - count(mid + 1, r, c)) + recur(l, mid, c + 1, ans));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> s;
    int ans = 0;
    cout << recur(0, n - 1, 'a', &ans) << '\n';
  }
  return 0;
}
