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