#include <bits/stdc++.h>
using namespace std;
int v[200000];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int minx = 10000000;
    int r = 0;
    for (int i = 1; i <= n; i++) cin >> v[i];
    for (int i = n; i >= 1; i--) {
      minx = min(v[i], minx);
      if (v[i] > minx) r++;
    }
    cout << r << endl;
  }
}
