#include <bits/stdc++.h>
using namespace std;
char s[45];
char cpy[45];
void solve() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  strcpy(cpy, s);
  sort(cpy, cpy + n);
  int k = 0;
  for (int i = 0; cpy[i] != '\0'; i++)
    if (cpy[i] != s[i]) k++;
  printf("%d\n", k);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
