#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while ((t--)) {
    int n;
    cin >> n;
    int arr[n];
    int diff[n - 1];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int ctr = 0;
    int min = arr[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      if (min >= arr[i]) {
        min = arr[i];
      } else {
        ctr++;
      }
    }
    cout << ctr << "\n";
  }
  return 0;
}
