#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  string s1 = s;
  sort(s1.begin(), s1.end());
  int k = 0;
  for (int i = 0; i < n; i++) {
    if (s1[i] != s[i]) k++;
  }
  cout << k << endl;
  ;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
