#include <bits/stdc++.h>
using namespace std;
void solve() {
  int N;
  scanf("%d", &N);
  vector<int> A(N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  int mn = 1e9;
  int ans = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (A[i] > mn) {
      ans++;
    } else {
      mn = A[i];
    }
  }
  printf("%d\n", ans);
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
