#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
      int buf;
      cin >> buf;
      v.push_back(buf);
    }
    int ans = 0;
    int mp = v[n - 1];
    for (int i = n - 2; i >= 0; --i) {
      if (v[i] <= mp) {
        mp = v[i];
      } else {
        ++ans;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
