#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    char s[50];
    int s1[100], s2[100];
    cin >> n;
    cin >> s;
    for (int i = 0; i < n; i++) {
      s1[i] = s[i];
      s2[i] = s[i];
    }
    sort(s1, s1 + n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (s1[i] != s2[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
