#include <bits/stdc++.h>
using namespace std;
int red(int &x) { return scanf("%d", &x); }
int red(int &x, int &y) { return scanf("%d %d", &x, &y); }
int red(int &x, int &y, int &z) { return scanf("%d %d %d", &x, &y, &z); }
int red(long long &x) { return scanf("%lld", &x); }
int red(long long &x, long long &y) { return scanf("%lld %lld", &x, &y); }
int red(long long &x, long long &y, long long &z) {
  return scanf("%lld %lld %lld", &x, &y, &z);
}
const int mod = 1000000000 + 7;
const int maxn = 500100;
char s[100];
void solve() {
  int n;
  red(n);
  scanf(" %s", s);
  string a(s, s + n);
  sort(a.begin(), a.end());
  int ans = n;
  for (int i = 0; i < n; i++) {
    if (s[i] == a[i]) ans--;
  }
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  red(t);
  for (int caso = 1; caso < t + 1; caso++) {
    solve();
  }
}
