#include <bits/stdc++.h>
using namespace std;
long long powerm(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long power(long long x, unsigned long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modInverse(long long a, long long m) {
  long long x, y;
  long long g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    cout << "Inverse doesn't exist";
  else {
    long long res = (x % m + m) % m;
    return res;
  }
}
long long vis[200001];
long long dps[200001];
long long dpt[200001];
long long par[200001];
long long tin[200001];
long long tout[200001];
long long t = 0;
long long dx[] = {0, 1, -1, 0};
long long dy[] = {1, 0, 0, -1};
struct setcmp {
  bool operator()(long long x, long long y) { return x < y; }
};
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long p;
  long long dp[26][n + 1];
  for (long long i = 0; i < 26; i++) {
    for (long long j = 0; j <= n; j++) dp[i][j] = 0;
  }
  s = '#' + s;
  for (long long i = 1; i <= n; i++) {
    dp[s[i] - 'a'][i]++;
  }
  for (long long i = 0; i < 26; i++) {
    for (long long j = 1; j <= n; j++) dp[i][j] = dp[i][j - 1] + dp[i][j];
  }
  long long l = 1, r = n, t = n / 2;
  long long c = 0;
  p = 0;
  while (p <= t) {
    long long m = (l + r) / 2;
    long long v1 = dp[p][m] - dp[p][l - 1];
    long long v2 = dp[p][r] - dp[p][m];
    if (v1 >= v2) {
      c += (m - l + 1) - (v1);
      l = m + 1;
    } else {
      c += (r - m) - (v2);
      r = m;
    }
    p++;
  }
  cout << c;
}
int32_t main() {
  long long qq = 1;
  cin >> qq;
  long long t = 1;
  while (qq--) {
    solve();
    cout << "\n";
    t++;
  }
}
