#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    vector<int> arr(N);
    for (auto& x : arr) cin >> x;
    vector<int> pref(N);
    pref[N - 1] = arr[N - 1];
    for (int i = N - 2; i >= 0; i--) pref[i] = min(pref[i + 1], arr[i]);
    int res = 0;
    for (int i = 0; i < N; i++) {
      if (pref[i] != arr[i]) res++;
    }
    cout << res << "\n";
  }
}
