#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int a[N], s[N];
int solve(int dau, int cuoi, int b) {
  if (dau == cuoi) {
    if (s[dau] == b)
      return 0;
    else
      return 1;
  }
  int mid = (dau + cuoi) / 2;
  int maxx = 1e9, res1 = 0, res2 = 0;
  for (int i = 1; i <= mid; i++)
    if (b != s[i]) res1++;
  for (int i = mid + 1; i <= cuoi; i++)
    if (b != s[i]) res2++;
  maxx = min(res2 + solve(dau, mid, b + 1), res1 + solve(mid + 1, cuoi, b + 1));
  return maxx;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    int n, res = 1e9;
    char a;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a, s[i] = int(a - 96);
    cout << solve(1, n, 1) << endl;
  }
}
