#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  int t, minl, n, ans;
  int a[150000 + 10];
  cin >> t;
  while (t--) {
    cin >> n;
    ans = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = n; i >= 1; i--) {
      if (i == n)
        minl = a[i];
      else {
        if (a[i] > minl) {
          ans++;
        } else {
          minl = a[i];
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
