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