#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, b;
  vector<int> x;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    x.clear();
    for (int j = 0; j < n; j++) {
      cin >> b;
      x.push_back(b);
    }
    int mn = x[n - 1];
    int cnt1 = 0;
    for (int j = n - 2; j >= 0; j--) {
      if (x[j] > mn) {
        cnt1++;
      } else {
        mn = x[j];
      }
    }
    cout << cnt1 << endl;
  }
}
