#include <bits/stdc++.h>
using namespace std;
const int MAXN = 45;
char a[MAXN];
char b[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> a;
    for (int i = 0; i < n; i++) b[i] = a[i];
    sort(b, b + n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
