#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int n, a[150000]{};
    cin >> n;
    for (int j = 0; j < n; ++j) {
      cin >> a[j];
    }
    int min = a[n - 1], cnt = 0;
    for (int j = n - 2; j >= 0; --j) {
      if (a[j] < min) {
        min = a[j];
      } else if (a[j] > min) {
        ++cnt;
      }
    }
    cout << cnt << "\n";
  }
  return 0;
}
