#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  int n;
  cin >> t;
  for (int u = 0; u < t; u++) {
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    vector<int> v;
    int mini = arr[n - 1];
    for (int i = (n - 2); i >= 0; i--) {
      if (mini < arr[i])
        v.push_back(arr[i]);
      else
        mini = arr[i];
    }
    cout << v.size() << "\n";
  }
  return 0;
}
