#include <bits/stdc++.h>
using namespace std;
int main() {
  int r[10000];
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    int n, min;
    int days[150000];
    r[k] = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> days[i];
    min = days[n - 1];
    for (int i = (n - 2); i >= 0; i--) {
      if (days[i] > min) {
        r[k]++;
      } else if (days[i] < min) {
        min = days[i];
      }
    }
  }
  for (int i = 0; i < t; i++) cout << r[i] << endl;
  return 0;
}
