#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
char s[N];
int ans;
void dfs(int l, int r, int cnt, char c) {
  if (l == r) {
    if (s[l] != c) cnt++;
    ans = min(ans, cnt);
    return;
  }
  int cnt1 = 0, cnt2 = 0, mid = l + r >> 1;
  for (int i = l; i <= mid; i++)
    if (s[i] != c) cnt1++;
  for (int i = mid + 1; i <= r; i++)
    if (s[i] != c) cnt2++;
  dfs(l, mid, cnt + cnt2, c + 1);
  dfs(mid + 1, r, cnt + cnt1, c + 1);
}
int main() {
  int t, n;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%s", &n, s + 1);
    ans = n;
    dfs(1, n, 0, 'a');
    printf("%d\n", ans);
  }
  return 0;
}
