#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int curr = arr[n - 1];
    int ans = 0;
    for (int i = n - 2; i >= 0; --i) {
      curr = min(arr[i], curr);
      if (curr != arr[i]) ans++;
    }
    cout << ans << "\n";
  }
}
