#include <bits/stdc++.h>
using namespace std;
const int xx = 1e8;
const long long oo = 1e18;
void Suhaib_Sawalha() {
  int n;
  cin >> n;
  int arr[n], Min(INT_MAX), ans(0);
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = n - 1; i >= 0; --i) {
    Min = min(Min, arr[i]);
    if (arr[i] > Min) ans++;
  }
  cout << ans << endl;
}
void Suhaib_Sawalha1() {
  long long t;
  cin >> t;
  while (t--) {
    Suhaib_Sawalha();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Suhaib_Sawalha1();
  return 0;
}
