#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n;
    string s;
    cin >> n >> s;
    string c = s;
    long long ans = 0;
    sort(c.begin(), c.end());
    for (long long i = 0; i < n; i++) {
      if (s[i] != c[i]) ans++;
    }
    cout << ans << endl;
  }
}
