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