#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int min = INT_MAX;
    int count = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (arr[i] > min)
        count++;
      else
        min = arr[i];
    }
    cout << count << endl;
  }
  return 0;
}
