#include <bits/stdc++.h>
using namespace std;
int a[150005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int dem = 0;
    ;
    for (int i = 0; i < n; i++) cin >> a[i];
    int mi = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      mi = min(mi, a[i]);
      if (a[i] > mi) dem++;
    }
    cout << dem << endl;
  }
  return 0;
}
