#include <bits/stdc++.h>
using namespace std;
const int N = 150000 + 5;
int a[N];
int main() {
  int T, n, m;
  cin >> T;
  while (T--) {
    int s = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    m = a[n];
    for (int i = n - 1; i >= 1; i--) {
      if (a[i] > m)
        s++;
      else
        m = a[i];
    }
    cout << s << endl;
  }
  return 0;
}
