#include <bits/stdc++.h>
using namespace std;
int t;
int k;
string s;
int a[27];
vector<char> v;
int main() {
  scanf("%d", &t);
  while (t--) {
    v.clear();
    scanf("%d", &k);
    cin >> s;
    int ans = 0;
    for (int i = 0; i < k; i++) v.push_back(s[i]);
    sort(v.begin(), v.end());
    for (int i = 0; i < s.length(); i++)
      if (s[i] != v[i]) ans++;
    printf("%d\n", ans);
  }
  return 0;
}
