#include <bits/stdc++.h>
using namespace std;
int a[150001];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    int minn = a[n - 1];
    int cnt = 0;
    for (int i = n - 2; i >= 0; i--) {
      if (a[i] > minn)
        cnt++;
      else
        minn = a[i];
    }
    cout << cnt << endl;
  }
}
