#include <bits/stdc++.h>
using namespace std;
int solve(int* arr, int n) {
  int cnt = 0, head = arr[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    if (arr[i] > head)
      ++cnt;
    else {
      head = arr[i];
    }
  }
  return cnt;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int* arr = new int[n];
    for (int i = 0; i < n; ++i) cin >> arr[i];
    cout << solve(arr, n) << endl;
    delete arr;
  }
  return 0;
}
