#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main() {
  int t, n, l = 0;
  cin >> t;
  while (t--) {
    cin >> n;
    l = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    int d = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      if (a[i] <= d)
        d = a[i];
      else
        l++;
    }
    cout << l << endl;
    std::fill(a, a + n, 0);
  }
}
