#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int num_query;
  cin >> num_query;
  while (num_query--) {
    int n;
    cin >> n;
    vector<int> seq(n);
    for (int i = 0; i < n; ++i) {
      cin >> seq[i];
    }
    vector<int> memo(n);
    memo[n - 1] = seq[n - 1];
    for (int i = n - 2; i >= 0; --i) {
      if (seq[i] <= memo[i + 1]) {
        memo[i] = seq[i];
      } else {
        memo[i] = memo[i + 1];
      }
    }
    int acc = 0;
    for (int i = 0; i < n; ++i) {
      if (seq[i] == memo[i]) {
        ++acc;
      }
    }
    cout << n - acc << '\n';
  }
  return EXIT_SUCCESS;
}
