#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(a % b, b);
}
int lis(string arr, int n) {
  int lis[n];
  lis[0] = 1;
  for (int i = 1; i < n; i++) {
    lis[i] = 1;
    for (int j = 0; j < i; j++)
      if (arr[i] > arr[j] && lis[i] < lis[j] + 1) lis[i] = lis[j] + 1;
  }
  return *max_element(lis, lis + n);
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    string l;
    for (int i = 0; i < n; i++) {
      l.push_back(s[i]);
    }
    sort(l.begin(), l.end());
    int cnt = 0;
    for (size_t i = 0; i < n; i++) {
      if (l[i] != s[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
