#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t, n, cnt;
  cin >> t;
  while (t--) {
    cnt = 0;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long min = a[n - 1];
    for (long long j = n - 2; j >= 0; j--) {
      if (a[j] > min)
        cnt++;
      else {
        min = a[j];
      }
    }
    cout << cnt << '\n';
  }
  return 0;
}
