#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c, countt = 0;
    cin >> a;
    vector<long long> A(a + 1);
    while (a--) {
      cin >> b;
      A.push_back(b);
    }
    c = A.back();
    for (long long i = A.size() - 1; i >= 0; i--) {
      if (A[i] > c)
        countt++;
      else
        c = A[i];
    }
    cout << countt << "\n";
    A.clear();
  }
}
