#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  ;
  cin.tie(NULL);
  ;
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    int ar[n];
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    int minn = 1e8, c = 0;
    for (int i = n - 1; i >= 0; i--) {
      minn = min(ar[i], minn);
      if (ar[i] == minn) {
        c++;
      }
    }
    cout << n - c << endl;
  }
}
