#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];
    int mn = INT_MAX;
    int cnt = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (v[i] > mn) cnt++;
      mn = min(mn, v[i]);
    }
    cout << cnt << "\n";
  }
}
