#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(true);
  int T;
  cin >> T;
  while (T--) {
    long long int n, min, k, days = 0;
    cin >> n;
    vector<long long int> v;
    for (long long int i = 0; i < n; i++) {
      cin >> k;
      v.emplace_back(k);
    }
    min = v[n - 1];
    for (long long int i = n - 2; i >= 0; i--) {
      if (v[i] > min)
        days++;
      else
        min = v[i];
    }
    cout << days << "\n";
  }
  return 0;
}
