#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
int n;
int t;
string s;
int c[26][maxn];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    cin >> s;
    if (s.length() == 1) {
      if (s == "a") {
        printf("0\n");
      } else
        printf("1\n");
      continue;
    }
    for (int i = 1; i <= s.length(); i++) {
      for (int j = 0; j < 26; j++) {
        if (s[i - 1] - 'a' == j)
          c[j][i] = c[j][i - 1] + 1;
        else
          c[j][i] = c[j][i - 1];
      }
    }
    int l = 1, r = n;
    int ans = 0, wjm = 0;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (c[wjm][mid] - c[wjm][l - 1] > c[wjm][r] - c[wjm][mid]) {
        ans += mid - l + 1 - (c[wjm][mid] - c[wjm][l - 1]);
        l = mid + 1;
      } else if (c[wjm][mid] - c[wjm][l - 1] < c[wjm][r] - c[wjm][mid]) {
        ans += r - mid - (c[wjm][r] - c[wjm][mid]);
        r = mid;
      } else {
        if (c[wjm + 1][mid] - c[wjm + 1][l - 1] <
            c[wjm + 1][r] - c[wjm + 1][mid]) {
          ans += mid - l + 1 - (c[wjm][mid] - c[wjm][l - 1]);
          l = mid + 1;
        } else {
          ans += r - mid - (c[wjm][r] - c[wjm][mid]);
          r = mid;
        }
      }
      wjm++;
    }
    ans += r - l + 1 - (c[wjm][r] - c[wjm][l - 1]);
    printf("%d\n", ans);
  }
}
