#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[150000] = {0};
  long long n, k, s = 0, kichik, t;
  cin >> t;
  for (int j = 1; j <= t; j++) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    kichik = a[n - 1];
    for (int i = n - 1; i >= 0; i -= 1) {
      if (kichik < a[i])
        s += 1;
      else
        kichik = a[i];
    }
    cout << s << endl;
    s = 0;
  }
}
