#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    long long int count = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long int mn = a[n - 1];
    for (long long int i = n - 1; i >= 0; i--) {
      if (a[i] <= mn) {
        mn = min(mn, a[i]);
      } else {
        count++;
      }
    }
    cout << count << "\n";
  }
}
