#include <bits/stdc++.h>
using namespace std;
char a[131078];
char tree[131078 * 3];
void init(int b, int e, int node, char c) {
  if (b == e) {
    tree[node] = (a[b] == c) ? 0 : 1;
    return;
  }
  int left = node * 2;
  int right = (node * 2) + 1;
  int mid = (b + e) / 2;
  init(b, mid, left, c);
  init(mid + 1, e, right, c);
  tree[node] = tree[left] + tree[right];
}
int query(int b, int e, int node, int i, int j) {
  if (i > e || j < b) {
    return 0;
  }
  if (b >= i && e <= j) {
    return tree[node];
  }
  int left = 2 * node;
  int right = 2 * node + 1;
  int mid = (b + e) / 2;
  long double p1 = query(b, mid, left, i, j);
  long double p2 = query(mid + 1, e, right, i, j);
  return p1 + p2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    int n, i;
    cin >> n;
    string s;
    cin >> s;
    for (i = 0; i < n; i++) {
      a[i + 1] = s[i];
    }
    int lo = 1, hi = n;
    char c = 'a';
    int cnt = 0;
    while (1) {
      int mid = (lo + hi) / 2;
      if (lo == hi) {
        cnt += (a[lo] == c) ? 0 : 1;
        break;
      }
      init(lo, hi, (hi - lo + 1), c);
      int qq = query(lo, hi, (hi - lo + 1), lo, mid);
      int qqq = query(lo, hi, (hi - lo + 1), mid + 1, hi);
      if (qq >= qqq) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
      cnt += min(qq, qqq);
      c++;
    }
    cout << cnt << endl;
  }
}
