#include <bits/stdc++.h>
using namespace std;
int c[26][200001];
string st;
long long solve(int l, int r, char ch) {
  if (l == r) {
    if (ch == st[l]) return 0;
    return 1;
  }
  if (l > r) return 0;
  if (ch == 'z') {
    int res = c[25][r] - c[25][l];
    if (st[l] == 'z') res++;
    return res;
  }
  int m = (l + r) / 2;
  int cl = c[ch - 'a'][m] - c[ch - 'a'][l];
  if (st[l] == ch) cl++;
  int cr = c[ch - 'a'][r] - c[ch - 'a'][m + 1];
  if (st[m + 1] == ch) cr++;
  int ln = (m - l + 1);
  int ans = min(ln - cl, ln - cr);
  if (cl > cr) return ans + solve(m + 1, r, ch + 1);
  if (cr > cl) return ans + solve(l, m, ch + 1);
  if (cl == cr) return ans + min(solve(l, m, ch + 1), solve(m + 1, r, ch + 1));
}
int main() {
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> st;
    memset(c, 0, sizeof(0));
    c[st[0] - 'a'][0]++;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 26; j++) c[j][i] = c[j][i - 1];
      c[st[i] - 'a'][i]++;
    }
    cout << solve(0, n - 1, 'a') << '\n';
  }
}
