#include <bits/stdc++.h>
int main() {
  int t = 0;
  int n = 0;
  int bad = 0;
  int minD = 0;
  std::cin >> t;
  std::vector<int> answer;
  for (int i = 0; i < t; i++) {
    std::cin >> n;
    std::vector<int> digits(n);
    for (int i = 0; i < n; i++) {
      std::cin >> digits[i];
    }
    minD = digits[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      if (digits[i] <= minD) {
        minD = digits[i];
      } else {
        bad++;
      }
    }
    answer.push_back(bad);
    bad = 0;
  }
  for (auto iter : answer) {
    std::cout << iter << std::endl;
  }
  return 0;
}
