#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  for (long long y = 0; y < t; y++) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    string temp = s;
    sort(s.begin(), s.end());
    long long cnt = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] != temp[i]) cnt++;
    }
    cout << cnt << endl;
  }
}
