#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int t = 0; t < T; ++t) {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int& a : A) cin >> a;
    int M = A.back();
    int result = 0;
    for (int i = N - 1; i >= 0; --i)
      if (M >= A[i])
        M = A[i];
      else
        ++result;
    cout << result << '\n';
  }
  return 0;
}
