#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, r = INT_MAX;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    r = a[n - 1];
    int c = 0;
    for (int i = n - 2; i >= 0; i--) {
      if (a[i] > r) c++;
      if (a[i] < r) r = a[i];
    }
    cout << c << endl;
  }
}
