#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n], i;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    int x = 0;
    int m = a[n - 1];
    for (i = n - 2; i >= 0; i--) {
      if (a[i] > m) x++;
      m = min(m, a[i]);
    }
    cout << x << "\n";
  }
}
