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