#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, ans = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int best = INT_MAX;
    for (int i = n - 1; i >= 0; i--) {
      if (v[i] > best) ans++;
      ;
      best = min(best, v[i]);
    }
    cout << ans << endl;
  }
}
