#include <bits/stdc++.h>
using namespace std;
int n;
char ch[500015];
int p[500010], ar[500015][26];
void solve(int x = 1, int y = 1, int z = n) {
  if (y == z) {
    for (int i = 0; i < 25; i++) {
      ar[x][i] = (ch[y] != ('a' + i));
    }
    return;
  }
  int c = (y + z) / 2;
  for (int i = 0; i < 24; i++) {
    if (ar[x * 2][i + 1] < 0) {
      solve(x * 2, y, c);
    }
    if (ar[x * 2 + 1][i + 1] < 0) {
      solve(x * 2 + 1, c + 1, z);
    }
    int res1 = 0, res2 = 0;
    for (int j = y; j <= c; j++) {
      res1 += (ch[j] != ('a' + i));
    }
    for (int j = c + 1; j <= z; j++) {
      res2 += (ch[j] != ('a' + i));
    }
    ar[x][i] = min(ar[x * 2 + 1][i + 1] + res1, res2 + ar[x * 2][i + 1]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> ch[i];
    for (int i = 1; i <= 2 * n; i++) {
      for (int j = 0; j < 25; j++) {
        ar[i][j] = -1;
      }
    }
    solve();
    cout << ar[1][0] << endl;
  }
}
