#include <bits/stdc++.h>
using namespace std;
int T, n, num, maxn;
char s[131077];
int a[131077][26], g[26];
void dfs(int l, int r, int sum, char c, int tmp) {
  if (!tmp) {
    if (a[l][c - 'a']) ++sum;
    maxn = max(maxn, sum);
    return;
  }
  int mid = (r - l + 1) / 2 + l;
  dfs(l, mid - 1, sum + a[mid / tmp][c - 'a'], c + 1, tmp >> 1);
  dfs(mid, r, sum + a[l / tmp][c - 'a'], c + 1, tmp >> 1);
}
int main() {
  cin >> T;
  while (T--) {
    memset(g, 0, sizeof(g));
    cin >> n;
    scanf("%s", s);
    int tmp = n;
    num = 0;
    maxn = 0;
    while (tmp) ++num, tmp >>= 1, g[num - 1] = tmp;
    g[num - 1] = 1;
    tmp = n;
    for (int i = 0; i < n; ++i) {
      if (s[i] <= 'a' + num - 1) a[i / g[s[i] - 'a']][s[i] - 'a']++;
    }
    dfs(0, n - 1, 0, 'a', n / 2);
    cout << n - maxn << endl;
    for (int i = 0; i < n; ++i) {
      if (s[i] <= 'a' + num - 1) a[i / g[s[i] - 'a']][s[i] - 'a']--;
    }
  }
}
