#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int t, n;
string s, x;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> s;
    x = s;
    sort(x.begin(), x.end());
    int ans = n;
    for (int i = 0; i <= n - 1; ++i) ans -= (s[i] == x[i]);
    cout << ans << '\n';
  }
}
