#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, char *argv[]) {
  clock_t start = clock();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int cases;
  cin >> cases;
  while (cases--) {
    int n, i, mini = INT_MAX, res = 0;
    cin >> n;
    vector<pair<int, int> > A(n);
    for (i = 0; i < n; i++) cin >> A[i].first;
    for (i = n - 1; i >= 0; i--) {
      mini = min(mini, A[i].first);
      A[i].second = min(A[i].first, mini);
    }
    for (i = 0; i < n; i++)
      if (A[i].first > A[i].second) res++;
    cout << res << endl;
  }
  cerr << "Execution Time: " << fixed
       << double(clock() - start) / double(CLOCKS_PER_SEC) << setprecision(6)
       << " sec\n";
}
