#include <bits/stdc++.h>
using namespace std;
int a[150001];
void query() {
  int n, kq = INT_MAX, d = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = n; i >= 1; --i) {
    if (a[i] <= kq) {
      kq = a[i];
      continue;
    } else {
      ++d;
    }
  }
  cout << d << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 1; i <= t; ++i) query();
  return 0;
}
